raphw / byte-buddy

Runtime code generation for the Java virtual machine.
https://bytebuddy.net
Apache License 2.0
6.29k stars 807 forks source link

how to enhance thread construct method #1627

Closed githubcheng2978 closed 1 month ago

githubcheng2978 commented 6 months ago

how to enhance thread construct method ?

githubcheng2978 commented 6 months ago
image

it is not work~

raphw commented 6 months ago

The Thread class will already be loaded, so you likely will need to apply retransformation. Typically, you'd also disable class format changes doing so. There's steps for both in the DSL.

githubcheng2978 commented 6 months ago

Thank you very much for your answer.because lambda Runnable didn’t can be interceptor, so I want interceptor Thread construct method,then delegate lambda .

获取 Outlook for iOShttps://aka.ms/o0ukef


发件人: Rafael Winterhalter @.> 发送时间: Tuesday, April 30, 2024 12:46:10 AM 收件人: raphw/byte-buddy @.> 抄送: githubcheng2978 @.>; Author @.> 主题: Re: [raphw/byte-buddy] how to enhance thread construct method (Issue #1627)

The Thread class will already be loaded, so you likely will need to apply retransformation. Typically, you'd also disable class format changes doing so. There's steps for both in the DSL.

― Reply to this email directly, view it on GitHubhttps://github.com/raphw/byte-buddy/issues/1627#issuecomment-2083201404, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AFISMWBFD4IMBLY2GVROWIDY7Z2NFAVCNFSM6AAAAABG5RVBKWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOBTGIYDCNBQGQ. You are receiving this because you authored the thread.Message ID: @.***>

githubcheng2978 commented 6 months ago

So, what should I do to intercept the thread's constructor? Can you give me a dmeo?

raphw commented 6 months ago

You can intercept a constructor just as any method. Intercept via ElementMatchers.isConstructor().

githubcheng2978 commented 6 months ago
image

it is not work~~~

raphw commented 6 months ago

skip the explicit retransformClasses.

Also, add .wtih(RetransformationStrategy.RETRANSFORM).disableClassFormatChanges().