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

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -