Hello MicroEJ Team,
I am porting System View functionalities on my platform following this documentation : SystemView — MicroEJ Documentation
But I don’t know how I can change my tasks names, in System View they seem to appear with a generic name (Thread 1 for instance).
How can I rename the Java tasks?
Regards,
Philip
Hi Philip,
The Java threads are named (not only in the context of System View).
Please refer to Thread Javadoc.
It is possible to set the name of a thread:
- at creation, using the contructor:
new Thread(myRunnable, "MY_THREAD");
- after creation, using the setter:
myThread.setName("MY_THREAD");
Best regards,
Rémy
Hi Remy,
Thanks for the info but I’m using a Timer and some TimerTask not directly a Thread.
If I understood correctly this is the Thread created by the Timer that I see in System View but I cannot access and rename it. Either with a constructor or the setName method.
Is there any other way to be able to identify this Thread/Timer?
Regards
Philip,
Indeed, System View shows the thread used by the timer.
TimerTask
is just a Runnable
that System View is not aware of.
Regarding Timer
, I suppose you are using the ej.bon.Timer
class.
The deprecated java.util.Timer
class has one constructor that takes the name of the underlying thread as its argument.
Indeed, ej.bon.Timer
does not provide an API to control the name of the thread.
Still, you can change the name of the timer thread using the setter within a TimerTask
:
timer.schedule(new TimerTask() {
@Override
public void run() {
Thread.currentThread().setName("MY_THREAD");
}
}, 0);
Yet, in my opinion, the best way to do it is to use a custom thread:
final Timer timer = new Timer(false);
new Thread(new Runnable() {
@Override
public void run() {
timer.run();
}
}, "MY_THREAD").start();
Best regards,
Rémy
Thanks Rémy, that did the trick.
Regards,
Philip