lishunli / projectlombok

Automatically exported from code.google.com/p/projectlombok
0 stars 0 forks source link

Synchronized with Reentrantlock #575

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Can you add ability to generate from this:
@Reentrant(lock)
public static hello(){
        System.out.println("world");
}

that:
public static void hello() {
    lock.lock();
    try{
        System.out.println("world");
    }finally{
        lock.unlock
    }
}

Original issue reported on code.google.com by theasp...@gmail.com on 17 Sep 2013 at 5:18

GoogleCodeExporter commented 9 years ago

Original comment by askon...@gmail.com on 7 Oct 2013 at 8:13

GoogleCodeExporter commented 9 years ago
This could be extended by `ReadLock` and `WriteLock` (and whatever...). I 
guess, the distinction between read and write access is the most common reason 
why `synchronized` (or `@Synchronized`) can't be used.

Concerning the syntax, maybe

@Lock(lock)
@Lock.Read(lock)
@Lock.Write(lock)

could do. Omitting the argument could use a lombok-generated lock (just like 
@Synchronized does).

Original comment by Maaarti...@gmail.com on 15 Oct 2013 at 2:39