< prev index next >

src/java.base/share/classes/sun/nio/ch/FileChannelImpl.java

Print this page
rev 14210 : 8154231: Simplify access to System properties from JDK code
Reviewed-by: rriggs


1002 
1003 
1004 
1005     // keeps track of locks on this file
1006     private volatile FileLockTable fileLockTable;
1007 
1008     // indicates if file locks are maintained system-wide (as per spec)
1009     private static boolean isSharedFileLockTable;
1010 
1011     // indicates if the disableSystemWideOverlappingFileLockCheck property
1012     // has been checked
1013     private static volatile boolean propertyChecked;
1014 
1015     // The lock list in J2SE 1.4/5.0 was local to each FileChannel instance so
1016     // the overlap check wasn't system wide when there were multiple channels to
1017     // the same file. This property is used to get 1.4/5.0 behavior if desired.
1018     private static boolean isSharedFileLockTable() {
1019         if (!propertyChecked) {
1020             synchronized (FileChannelImpl.class) {
1021                 if (!propertyChecked) {
1022                     String value = AccessController.doPrivileged(
1023                         new GetPropertyAction(
1024                             "sun.nio.ch.disableSystemWideOverlappingFileLockCheck"));
1025                     isSharedFileLockTable = ((value == null) || value.equals("false"));
1026                     propertyChecked = true;
1027                 }
1028             }
1029         }
1030         return isSharedFileLockTable;
1031     }
1032 
1033     private FileLockTable fileLockTable() throws IOException {
1034         if (fileLockTable == null) {
1035             synchronized (this) {
1036                 if (fileLockTable == null) {
1037                     if (isSharedFileLockTable()) {
1038                         int ti = threads.add();
1039                         try {
1040                             ensureOpen();
1041                             fileLockTable = FileLockTable.newSharedFileLockTable(this, fd);
1042                         } finally {
1043                             threads.remove(ti);
1044                         }




1002 
1003 
1004 
1005     // keeps track of locks on this file
1006     private volatile FileLockTable fileLockTable;
1007 
1008     // indicates if file locks are maintained system-wide (as per spec)
1009     private static boolean isSharedFileLockTable;
1010 
1011     // indicates if the disableSystemWideOverlappingFileLockCheck property
1012     // has been checked
1013     private static volatile boolean propertyChecked;
1014 
1015     // The lock list in J2SE 1.4/5.0 was local to each FileChannel instance so
1016     // the overlap check wasn't system wide when there were multiple channels to
1017     // the same file. This property is used to get 1.4/5.0 behavior if desired.
1018     private static boolean isSharedFileLockTable() {
1019         if (!propertyChecked) {
1020             synchronized (FileChannelImpl.class) {
1021                 if (!propertyChecked) {
1022                     String value = GetPropertyAction.getProperty(
1023                             "sun.nio.ch.disableSystemWideOverlappingFileLockCheck");

1024                     isSharedFileLockTable = ((value == null) || value.equals("false"));
1025                     propertyChecked = true;
1026                 }
1027             }
1028         }
1029         return isSharedFileLockTable;
1030     }
1031 
1032     private FileLockTable fileLockTable() throws IOException {
1033         if (fileLockTable == null) {
1034             synchronized (this) {
1035                 if (fileLockTable == null) {
1036                     if (isSharedFileLockTable()) {
1037                         int ti = threads.add();
1038                         try {
1039                             ensureOpen();
1040                             fileLockTable = FileLockTable.newSharedFileLockTable(this, fd);
1041                         } finally {
1042                             threads.remove(ti);
1043                         }


< prev index next >