dcsimg
Multithreading question
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Paul_Hunnisett
Posted On:   Friday, August 9, 2002 09:22 AM

My application uses a class (called LombokServerConnection) that extends Thread. This is called in the followng way:

while(true){

try {

new LombokServerConnection(lombok.sock.accept(), lombok.context, lombok.root).start();


}

catch (IOException e){

System.out.println("Could not get connection " + e);

}

}

Will any instance variables of this class (Lombok
ServerConnection) be shared by the threads, or wil lthey all have their own?

Re: Multithreading question

Posted By:   Mike_Friedrich  
Posted On:   Sunday, August 11, 2002 01:47 AM

You have to care only for those objects you provide with the constructor.


These are:


  • lombok.context,
  • lombok.root

These objects are shared by the threads.


lombok.sock.accept() returns a new socket object and therefore its not a problem (asuming this is a ServerSocket.accept()).


Regards, Mike

Re: Multithreading question

Posted By:   Anonymous  
Posted On:   Saturday, August 10, 2002 05:58 AM

They have all their own variables because you are creating always a new object. Use static class variables or externalize variables into a separate class to share them between the threads. Use synchronization, if you access shared variables.

About | Sitemap | Contact