<font color=red>Could you pls explain this?</font>
2 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sabu_vs
Posted On:   Saturday, August 24, 2002 01:12 AM

Hi I have a java program that calls another class for printing some data ----------------- class A Vector vect; //adding some data to vector //calling another class for printing b=new class B(); b.printData(vect); vect.removeAllElements(); If the second class is not a background thread the program works normally ie the program add some data to vector then calls the printdata method of class b. after the method finishes the program removes all the data from vector. But if Class B is a backgrou   More>>

Hi



I have a java program that calls another class for printing some data



-----------------


class A


Vector vect;



//adding some data to vector



//calling another class for printing

b=new class B();


b.printData(vect);



vect.removeAllElements();






If the second class is not a background thread the program works normally


ie the program add some data to vector then calls the

printdata method of class b. after the method finishes the program

removes all the data from vector.



But if Class B is a background thread what will happen?. The program calls the printData method

of class b; but before finishing the method [since class B is a thread] the program calls

the remove elements of the vector [there is no Thread.join() method here]


could you pls tell me what will happen in this scenaria.Could you pls explainnit?





thanks



sabu

   <<Less

Re: Could you pls explain this?

Posted By:   Jeanne_Boyarsky  
Posted On:   Saturday, August 24, 2002 10:19 AM

You would get an unpredicable result (depends on your OS and some random events.) If class A really should be clearing out the vector, you should use the synchronized keyword to get a lock on the vector before printing/deleting from it.

Re: <font color=red>Could you pls explain this?</font>

Posted By:   Lunkwill_Vroomfondel  
Posted On:   Saturday, August 24, 2002 03:23 AM

since i dont know what class B does, i can not explain what is going to happen.



but i would hint you this:

put the remove-method within class-B's run-method (after having printed).



dont forget to "start()" class B.
About | Sitemap | Contact