multithreading - Thread count is different when debugging and Running the porgramme -
i using following code :-
public static void main(string[] args) { int threadpool = 4; system.out.println("intital count---" + thread.activecount()); thread.currentthread(); }
the output different while debugging on intellij :- intital count---1
while running on intellij :- intital count---2
i not able understand thread in when run program.
there 1 thread made intellij when running it:
"monitor ctrl-break" java.lang.thread.state: runnable @ java.net.dualstackplainsocketimpl.accept0(native method) @ java.net.dualstackplainsocketimpl.socketaccept(dualstackplainsocketimpl.java:131) @ java.net.abstractplainsocketimpl.accept(abstractplainsocketimpl.java:398) @ java.net.plainsocketimpl.accept(plainsocketimpl.java:199) @ java.net.serversocket.implaccept(serversocket.java:530) @ java.net.serversocket.accept(serversocket.java:498) @ com.intellij.rt.execution.application.appmain$1.run(appmain.java:90) @ java.lang.thread.run(thread.java:745)
you print them using:
/** http://crunchify.com/how-to-generate-java-thread-dump-programmatically/ */ public static string crunchifygeneratethreaddump() { final stringbuilder dump = new stringbuilder(); final threadmxbean threadmxbean = managementfactory.getthreadmxbean(); final threadinfo[] threadinfos = threadmxbean.getthreadinfo(threadmxbean.getallthreadids(), 100); (threadinfo threadinfo : threadinfos) { dump.append('"'); dump.append(threadinfo.getthreadname()); dump.append("\" "); final thread.state state = threadinfo.getthreadstate(); dump.append("\n java.lang.thread.state: "); dump.append(state); final stacktraceelement[] stacktraceelements = threadinfo.getstacktrace(); (final stacktraceelement stacktraceelement : stacktraceelements) { dump.append("\n @ "); dump.append(stacktraceelement); } dump.append("\n\n"); } return dump.tostring(); }
Comments
Post a Comment