• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

thread quiting (basic)

 
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just look here
Thread t1=new Thread(this);
Thread t2=new Thread(this);
t1.start();
t2.start();
so we started two Threads then within run method
public void run(){
meth1();
meth2();
}
so we called two methods.My questien is when one of the Threads entered into run() it will defenetely quit after executing meth2()?.or if there is a chance of quiting after executing meth1() only?.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If meth1() does a System.exit() or throws an error or exception, the Thread will never get to meth2().
Bill
 
basha khan
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank u william i am very glad to see u here.so if there is no undesirable(Sys.exit(),excep etc)conditions,both methods will be executed by the entered Thread.
just look
------------------
block (1)
public void run(){
meth1();
meth2();
}
--------------------
block (2)
public synchronized void run(){
meth1();
meth2();
}
--------------------------
what is the deference between two blocks??.if any??
(I dont want to use any wait() or notify())
 
Ranch Hand
Posts: 203
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The difference is one is synchronised and the other is not.
In the unsynchronised scenario both the threads will start executing meth1 and meth2 based on when the thread scheuduler and the underlying OS lets each thread 'run'.
In the Synchronized scenario,when you start the two threads, whichever gets to to the 'Running' state first will start to execute the Run method ( and hence Meth1 and meth2 ). Only when it completes executing both methods, the next thread will be able to start Running.

HTH
reply
    Bookmark Topic Watch Topic
  • New Topic