What will happen in the following mulththreaded scenario?

Nilesh

Suppose I have a class where in the have methods synchronized in the way as follows.

public class Test{
    public static synchronized void method1(){
    }
    public static synchronized void method2(){
    }
    public synchronized void method3(){
    }
    public synchronized void method4(){
    }
}

So there is a scenario when two threads are calling method1 and method2 simultaneously.I feel that only one of the methods be allowed to call.What will be the case if they call method1 and method3.Will there be a same scenario here too?what will be the case with method3 and method4 from same object?

Patricia Shanahan

If you have two objects of class Test, referenced by x and y, there will be three monitors, one for Test, one for x, and one for y.

method1 and method2 both use the Test monitor, and so exclude each other. method3 and method4 each use the monitor for their target object, so they exclude each other if called for the same object, but not if called for different objects. They don't involve the Test monitor, so they don't exclude the static methods.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What pattern to use for the following scenario?

From Dev

What pattern to use for the following scenario?

From Dev

What's the issue in hide/show in jQuery code for following scenario?

From Dev

What's the issue in accessing associative array element in smarty in following scenario?

From Dev

Is the following scenario possible with Twilio

From Dev

SAS for the following scenario

From Dev

How to manipulate the array in following scenario?

From Dev

How to change the array in following scenario?

From Dev

Does SSD obsolete following scenario

From Dev

Design pattern to handle following scenario

From Dev

How to get result in following scenario

From Dev

SQL Query - stuck on the following scenario:

From Dev

How to get result in following scenario

From Dev

How to deal with following scenario in QTP?

From Dev

What happen with further clicks

From Dev

What is the $scenario variable in Codeception?

From Dev

What is the "click()" element in this scenario?

From Dev

Why does initialization happen in the following case?

From Dev

How to use RethinkDB indices in the following scenario?

From Dev

How would I improve the performance in the following scenario

From Dev

WHy the call is not going to the jQuery function in following scenario?

From Dev

How to use threading or Task pattern in following scenario

From Dev

How to use expandable list view in the following scenario

From Dev

SAS for following scenario (most frequent observation)

From Dev

How to show the groupwise result for the following scenario?

From Dev

How to make the checkbox working properly in following scenario?

From Dev

how to make a left outer join in following scenario

From Dev

Why the resource ID is not accessible in following scenario.?

From Dev

How to use threading or Task pattern in following scenario

Related Related

  1. 1

    What pattern to use for the following scenario?

  2. 2

    What pattern to use for the following scenario?

  3. 3

    What's the issue in hide/show in jQuery code for following scenario?

  4. 4

    What's the issue in accessing associative array element in smarty in following scenario?

  5. 5

    Is the following scenario possible with Twilio

  6. 6

    SAS for the following scenario

  7. 7

    How to manipulate the array in following scenario?

  8. 8

    How to change the array in following scenario?

  9. 9

    Does SSD obsolete following scenario

  10. 10

    Design pattern to handle following scenario

  11. 11

    How to get result in following scenario

  12. 12

    SQL Query - stuck on the following scenario:

  13. 13

    How to get result in following scenario

  14. 14

    How to deal with following scenario in QTP?

  15. 15

    What happen with further clicks

  16. 16

    What is the $scenario variable in Codeception?

  17. 17

    What is the "click()" element in this scenario?

  18. 18

    Why does initialization happen in the following case?

  19. 19

    How to use RethinkDB indices in the following scenario?

  20. 20

    How would I improve the performance in the following scenario

  21. 21

    WHy the call is not going to the jQuery function in following scenario?

  22. 22

    How to use threading or Task pattern in following scenario

  23. 23

    How to use expandable list view in the following scenario

  24. 24

    SAS for following scenario (most frequent observation)

  25. 25

    How to show the groupwise result for the following scenario?

  26. 26

    How to make the checkbox working properly in following scenario?

  27. 27

    how to make a left outer join in following scenario

  28. 28

    Why the resource ID is not accessible in following scenario.?

  29. 29

    How to use threading or Task pattern in following scenario

HotTag

Archive