• 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 & Synchronization

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please give me the possible answers and explanation for the following questions. Is there any different way to compile and run Thread Programs?in these in the normal way but no output.
Thanks in Advance,
Ushan.
que1)
------
class A extends Thread
{
private static String []A={"X","Y","Z"};
public void run()
{
System.out.println(A[0]+A[1]+A[2]);
}
public static void main(String aa[])
{
{
Thread t=new Thread();
System.out.println("AAAA");
t.start();
A[0]="A";A[1]="B";A[2]="C";
}
}

que2
-----

class A extends Thread
{
private static String []A={"X","Y","Z"};
public synchronized void run()
{
System.out.println(A[0]+A[1]+A[2]);
}
public static void main(String aa[])
{
synchronized(A) {
Thread t=new Thread();
System.out.println("AAAA");
t.start();
A[0]="A";A[1]="B";A[2]="C";
}

}
}
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

clarification needed Thread t= new Thread() or Thread t = new A();
 
Umashanthi Pavalanathan
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is Thread t=new Thread();
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Umashanthi,

I recommend to see Thread API, and see How to create a Thread which can execute your run().

All the best.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic