java - How to manipulate all active threads in a JavaFX application -
system.out.println(thread.activecount());
prints number of active threads.
right start application, says running 6 threads. how 1 go manipulate (say, priority of) these threads?
putting system.out.println(thread.currentthread().getname())
in code prints javafx application thread
.
you can use enumerate
method of thread
class. allow threads of thread group , copy them array.
a working example
import javafx.application.application; import javafx.stage.stage; public class threaddemo extends application { public static void main(string[] args) { launch(args); } @override public void start(stage stage) throws exception { int count = thread.activecount(); system.out.println("currently active threads = " + count); thread th[] = new thread[count]; // returns number of threads put array thread.enumerate(th); // set priority (int = 0; < count; i++) { // priority 0 not allowed th[i].setpriority(i + 1); system.out.println(i + ": " + th[i] + " has priority of " + th[i].getpriority()); } // check if change in priority reflected system.out.println("current thread " + thread.currentthread().getname() + " priority " + thread.currentthread().getpriority()); } }
Comments
Post a Comment