multithreading - Java: Thread ID changes during execution? -


i misunderstand in code regarding thread ids. trying follow execution order , doesn't help...

given following code creates threads:

private static void createnewworkerthreads() {          (int = 1; <= num_of_connections; i++) {              log4jwrapper.writelog(loglevelenum.debug, "[--------]\t<tier3loader> createnewworkerthreads", ":  create next work thread...");              workerthread workthread = new workerthread(donesignal);              if (workthread.init()) {                  thread t = new thread(workthread);                 t.start();                  arrworkthreadnew.add(workthread);             } else                 log4jwrapper.writelog(loglevelenum.error, "[---------]\t<tier3loader> createnewconferences", ": failed start workthread");              try {                 thread.sleep(nwaitbetweeneachconnectionms);             } catch (interruptedexception e) {                  log4jwrapper.writelog(loglevelenum.error, "[--------]\t<tier3loader> createnewworkerthreads", ":  " + e.getmessage());                  thread.currentthread().interrupt(); // restore interrupted state...             }         }      } 

and thread class code :

public workerthread(countdownlatch donesignal) {      this.donesignal = donesignal;     this.conferencework = new conferencework(this);      getdbconnections();  }  private void getdbconnections() {      try {         t2connection = dbcluster.getinstance().getnextt2db().getconnectionpool().getnextdbconnection();         if (t2connection != null)             log4jwrapper.writelog(loglevelenum.debug, "[---------]\t<workerthread" + thread.currentthread().getid() + "> getdbconnections", ": got t2 db connection...");         else             log4jwrapper.writelog(loglevelenum.debug, "[---------]\t<workerthread" + thread.currentthread().getid() + "> getdbconnections", ": failed t2 db connection...");          t2connection.setautocommit(true);      } catch (sqlexception e) {          exceptionhandler.printexception(e, "-----------", "workerthread", "getdbconnections", "failed t2 db connection");         return;     }      try {         t3connection = dbcluster.getinstance().gett3db().getconnectionpool().getnextdbconnection();         if (t3connection != null)             log4jwrapper.writelog(loglevelenum.debug, "[---------]\t<workerthread" + thread.currentthread().getid() + "> getdbconnections", ": got t3 db connection...");         else             log4jwrapper.writelog(loglevelenum.debug, "[---------]\t<workerthread" + thread.currentthread().getid() + "> getdbconnections", ": failed t3 db connection...");          t3connection.setautocommit(true);     } catch (sqlexception e) {         exceptionhandler.printexception(e, "-----------", "workerthread", "getdbconnections", "failed t3 db connection");     } }  public boolean init() {      log4jwrapper.initlog(log4j_properties_path);     dbcallsqueue.initlog(log4j_properties_path);      (new thread(new dbcallsexecuter(dbcallsqueue, obstop, lock, donesignal, lthreadid))).start();      return true; }  @override public void run() {      lthreadid = thread.currentthread().getid();     thread.currentthread().setname("workerthread" + lthreadid);      log4jwrapper.writelog(loglevelenum.debug, "[---------]\t<workerthread" + thread.currentthread().getid() + "> run", ": start flow...");      work(); } 

what see in log thread.currentthread().getid() in methods above except of run() 1, whereas in run() methods 16.

why that?

tal


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -