Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

This is related to threads. I have a class with synchronized
method m1(). Can I create different instances of this class
and execute the m1() for different threads?

Answer Posted / haneef

see by the synchronized it won't allow the other thread at a
time, but after completion of 1st thread it allows, so you
can create different instances.

see the following code

package app;

class C1 extends Thread {
public void run() {
m1();
}

public synchronized void m1() {
System.out.println("m1()");
}
}

public class Main {
public static void main(String[] args) {

C1 c1 = new C1();
C1 c2 = new C1();
C1 c3 = new C1();

Thread t1 = new Thread(c1);
Thread t2 = new Thread(c2);
Thread t3 = new Thread(c3);

t1.start();
t2.start();
t3.start();

}
}

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between multiple processes and multiple threads?

1183


What is final method in java?

1007


Why string is not thread safe?

993


Can we overload the constructors?

973


What is a boolean in java?

1037


What are methods of a class?

1016


Difference between method overloading and method overriding in java ?

1066


What is singletonlist in java?

948


What is the difference between serializable and externalizable interfaces?

1077


Define jre i.e. Java runtime environment?

992


Is ruby built on java?

934


Is object a data type?

950


What is meant by local variable and instance variable?

1007


What is a null point?

1036


What is widening and narrowing in java? Discuss with an example.

1030