java - Two instances of a class can call method (Synchronized on some object) parallelly -


i have method :

public void processchildnodes(node result, node source) {     synchronized (source) {         nodelist nodes = source.getchildnodes();         (int = 0; < nodes.getlength(); i++) {           processnode(result, nodes.item(i));         }     }   } 

now let trying call processchildnodes 2 different instances of class in method present same source (second parameter of method), possible 2 execution can go parallely??

you trying take object lock. if pass same object processing synchronized, means 1 thread executing code inside syncronized block , other thread waiting it. if passing 2 different objects use 2 different locks, means not dependent on each other take lock. both of them execute in parallel.

as have written code , trying synchronize execution using source object. make sure both of threads using same source object desired result.


Comments

Popular posts from this blog

php - cannot display multiple markers in google maps v3 from traceroute result -

php - Boolean search on database with 5 million rows, very slow -

css - Text drops down with smaller window -