Mercurial Hosting > luan
comparison src/luan/modules/ThreadLuan.java @ 1372:431d5bec3ca4
add Thread.new_synchronizer
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 01 Jul 2019 15:37:51 -0600 |
parents | ae2321a09723 |
children | 8d7a39ca2c0c |
comparison
equal
deleted
inserted
replaced
1371:4c5548a61d4f | 1372:431d5bec3ca4 |
---|---|
236 } | 236 } |
237 | 237 |
238 | 238 |
239 public static final ReadWriteLock backupLock = new ReentrantReadWriteLock(); | 239 public static final ReadWriteLock backupLock = new ReentrantReadWriteLock(); |
240 | 240 |
241 public static Object runInLock(Lock lock,LuanFunction fn) | 241 public static Object runInLock(Lock lock,LuanFunction fn,Object... args) |
242 throws LuanException, InterruptedException | 242 throws LuanException, InterruptedException |
243 { | 243 { |
244 if( !lock.tryLock(10,TimeUnit.MINUTES) ) | 244 if( !lock.tryLock(10,TimeUnit.MINUTES) ) |
245 throw new LuanException("failed to acquire lock"); | 245 throw new LuanException("failed to acquire lock"); |
246 try { | 246 try { |
247 return fn.call(); | 247 return fn.call(args); |
248 } finally { | 248 } finally { |
249 lock.unlock(); | 249 lock.unlock(); |
250 } | 250 } |
251 } | 251 } |
252 | 252 |