java - How do print out the name of thread currently running on a specific non-thread class? -
java - How do print out the name of thread currently running on a specific non-thread class? -
i've found answers on how print out name of specific thread when in class thread
or class subclassing thread
.
i.e. this.getname();
however, isn't working me when i'm in class queuemanager<t>
. illustration in method, removefromqueue()
, want print out thread pulling queue. when utilize this
, refers class queuemanager<t>
, not current thread.
how refer current thread within class?
public t removefromqueue(){ synchronized (this) { t item = null; if (!isempty()){ item = queue.removelast(); if (webserver.debug) system.out.println(item + " removed " + item.getclass() + "queue" + "\nby " + this.); //if queue total until right now, notify waiting socket threads can add together if (getsize() == (maxqueuesize - 1)){ notifyall(); } } homecoming item; //if queue empty, null returned. } }
the name of current thread given by
thread.currentthread().getname()
java multithreading this
Comments
Post a Comment