:confused:If there exists a class lock and from this class different thread objects or different objects & there corresponding threads are created, may they run simultaneously?:?:
e.g.

public class Smiley extends Thread {
 
               public void run() {
                while(true) {
                 try { synchronized(Smiley.class) {
                  System.out.print(":");
                  sleep(100);
                  System.out.print("-");
                  sleep(100);
                  System.out.print(")");
                  sleep(100); }
                 } catch (InterruptedException e) {
                  e.printStackTrace();
                 }
                }
               }

                public static void main() {
                new Smiley().start();
                new Smiley().start();
               }
              }

here in spite of instanciation of two separate thread objects (i.e. these are not common shared resource), is it due to having the common class lock which is preventing the other thread at synchronization?:icon_exclaim:
:icon_idea:With or without static methods, at the time of running, how much tasks are performed during class loading and what are left for the instances or objects? How these are related? Do they all happen at runtime? For which the JDK and JVM become liable? ......... :X

Recommended Answers

All 2 Replies

What is it with you and all these text decorations?
Anyway. Q1 answer No. Q2 answer Yes

Edit: Sorry misunderstood the question...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.