https://glazedlists.dev.java.net/issues/show_bug.cgi?id=251
Issue #|251 Summary|5.0 Lock Support Component|glazedlists Version|0.9.7 Platform|All OS/Version|All URL| Status|NEW Status whiteboard| Keywords| Resolution| Issue type|ENHANCEMENT Priority|P3 Subcomponent|core Assigned to|jessewilson Reported by|reden ------- Additional comments from [hidden email] Tue Jul 26 02:56:25 +0000 2005 ------- I'd like for GlazedLists to be able to use Java 5's locks rather than the Doug Lea implementation we're using right now to pick up on their extra speed. Obviously the funky part is to make sure it can compile and run under 1.4 and 5.0. So, here's my proposal: One class could be compiled under 5.0 and checked in as its ".class" form. When the jar is built, the class would be included. (The source would obviously be checked in somewhere, just not in the main source tree... or excluded from the ant build script.) If we decide that we don't want to include the 5.0 class, we could still do the LockFactory class and allow the user to specify their own implementation via a System property. Here's a LockFactory implementation that would do this: ------------------------ /** * Factory allows creation of the best locks for the VM we're running in. */ public class LockFactory { private static LockFactory instance; static { LockFactory jse5_lock_factory = null; // See if the user has specified their own lock factory implementation try { String user_lock_factory = System.getProperty("glazedlists.lockfactory", null); if (user_lock_factory != null) { try { jse5_lock_factory = (LockFactory) Class.forName( user_lock_factory).newInstance(); } catch (Exception ex) { System.err.println("Unable to load user-defined lock factory. " + "Default will be used."); ex.printStackTrace(); } catch (NoClassDefFoundError er) { System.err.println("Unable to load user-defined lock factory. " + "Default will be used."); er.printStackTrace(); } } } catch(SecurityException ex ) {} // ignore try { // See if we can find the 5.0 lock class Class.forName("java.util.concurrent.locks.ReentrantReadWriteLock"); // If so, see if we can load the 5.0 LockFactory class jse5_lock_factory = (LockFactory) Class.forName( "ca.odell.glazedlists.util.concurrent.JSE5LockFactory").newInstance(); } catch (Exception ex) {} // ignore catch (NoClassDefFoundError er) {} // ignore // See if we should print a debugging message saying what locks we're using boolean debug = false; try { debug = System.getProperty("glazedlists.lockfactory.debug",null) != null; } catch( SecurityException ex ) {} // ignore // Set the singleton instance if (jse5_lock_factory != null) { if (debug) System.out.println("*** GlazedLists will use 5.0+ Locking ***"); instance = jse5_lock_factory; } else { if (debug) System.out.println("*** GlazedLists will use 1.2+ Locking ***"); instance = new LockFactory(); } } /** * Create a new {@link ReadWriteLock}. */ public static ReadWriteLock createReadWriteLock() { return instance._internalCreateReadWriteLock(); } /** * Create a new {@link Lock}. */ public static Lock createLock() { return instance._internalCreateLock(); } /** * Should be overridden by LockFactory implementations to return a ReadWriteLock * implementation. The default implementation returns a {@link J2SE12ReadWriteLock}, * which works in 1.2+ VM's. */ protected ReadWriteLock _internalCreateReadWriteLock() { return new J2SE12ReadWriteLock(); } /** * Should be overridden by LockFactory implementations to return a Lock implementation. * The default implementation uses a {@link J2SE12ReadWriteLock}, which works in 1.2+ * VM's. */ protected Lock _internalCreateLock() { return new J2SE12ReadWriteLock().writeLock(); } } ------------------------ Implementing 5.0 support is them pretty easy. --------------------------------------------------------------------- To unsubscribe, e-mail: [hidden email] For additional commands, e-mail: [hidden email] |
Free forum by Nabble | Edit this page |