Thanks. In the following code, which object is synchronized?
public class TestThread implements Runnable
new Thread(this,"Test 1").start();
new Thread(this,"Test 22").start();
synchronized public void run()
System.out.println((i++)+"....Sync block 1 :"+Thread.currentThread().getName());
public static void main(String args) throws InterruptedException
During the execution of a synchronized method, the thread holds the monitor for that method's object, or if the method is static, it holds the monitor for that method's class. If another thread is executing the synchronized method, your thread is blocked until that thread releases the monitor (by either exiting the method or by calling wait()).
Sorry ramjeev, musthafa is right. "this" is the method's object.
See Java Lanmguage ref:
184.108.40.206 synchronized Methods
A synchronized method acquires a monitor (§17.1) before it executes. For a class (static) method, the monitor associated with the Class object for the method's class is used. For an instance method, the monitor associated with this (the object for which the method was invoked) is used.
I am writing a java program that needs to execute shell commands, so I wrote a function that would take the command to execute as a string (ie: "mkdir ~/Folder1") and execute that command with the shell. Here is the function:
Runtime run = Runtime.getRuntime();
Process pr = ...
Hey, so I wanna ask how I need to create a method who will remove word if in that word is 2 same chars. Example: "Potato" in this word there is a 2 "o" chars so this word will need to be removed. "Forum" in this word there is no ...
Help! I want to create a java program that finds the highest even integer among the values entered by the user. Stop asking values when a value less than 1 have been entered. If no even integer is entered, display "No Even Integer"