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 Doubt

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi Ranchers
please explain the following codes.when i run it gives output 00224466
is it vary or same bcaz 2 thread instance created.

but options are
A 0 2 4 4 6 8 10 6
B 0 2 4 6 8 10 2 4
C 0 2 4 6 8 10 12 14
D 0 0 2 2 4 4 6 6 8 8 10 10 12 12

questions :
class Thread1
{
int x=0;
public class Runner implements Runnable
{
public void run()
{
int cur=0;
for (int i=0;i<4 ;i++ )
{
cur=x;
System.out.println(cur +" ");
x=cur+2;
}
}
};
public static void main(String[] args)
{
(new Thread1()).go();
}
public void go()
{
Runnable r1=new Runner();
(new Thread(r1)).start();
(new Thread(r1)).start();
}
}
 
Ranch Hand
Posts: 274
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
DOUBLE POST,

https://coderanch.com/t/264885/java-programmer-SCJP/certification/Thread
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic