lsergio commented on PR #17389:
URL: https://github.com/apache/camel/pull/17389#issuecomment-2708532849
I was also wondering if the listener idea could be applied to thread
creation instead.
Camel would use a thread factory that creates an specific kind of thread
which would invoke the listeners. Something like:
```java
interface ThreadListener {
void onThreadStarted(Thread t);
void onThreadCompleted(Thread t);
}
class CamelThread extends Thread {
private Runnable task;
private ThreadListener listener;
public CamelThread(Runnable task, ThreadListener listener) {
this.task = task;
this.listener = listener;
}
@Override
public void run() {
listener.onThreadStarted(this);
try {
task.run();
} finally {
listener.onThreadCompleted(this);
}
}
}
public class Threads {
public static void main(String[] args) throws InterruptedException {
Runnable r = () -> { System.out.println("This is where the
async code runs");};
ThreadListener listener = new ThreadListener() {
@Override
public void onThreadStarted(Thread t) {
System.out.println("Sets the MDC info");
}
@Override
public void onThreadCompleted(Thread t) {
System.out.println("Clears the MDC info");
}
};
CamelThread thread = new CamelThread(r, listener);
thread.start();
thread.join();
}
}
```
Of course the core codebase is really large and complex and I may not be
taking into consideration a lot of aspects.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]