KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is there any way to check how many threads are waiting for a synchronized method to become unlocked? I would like to know when the thread calls a synchronized method: 1) How many threads are already waiting to call the method? 2) Once the method is called how long it needed to wait for the method to become unlocked? Solution: I solved this using stackers answer: public class LockedClass { public static int count; public static void measuringClass() throws IOException{ long startTime = System.currentTimeMillis(); count++; System.out.println("Threads waiting="+count); lockedMethod(startTime); count--; System.out.println("Threads waiting="+count); } public static synchronized void lockedMethod(long startTime) throws IOException{ System.out.println("I spent="+(System.currentTimeMillis()-startTime)+" in the queue"); Hashtable<String, String> params = new Hashtable<String, String>(); params.put("param1", "test"); params.put("param2", "12345678"); String sessionId = Common.getSession(Common.executeHttpRequest(params)); } }
Tags (comma-separated)
Save Edits
Cancel