Regis, This breaks the build for the IBM VME (from developerWorks). Since they don't have a sun.misc.Unsafe, so the AtomicInteger can't be resolved.
Any ideas how to fix this? Also, the luni.jar manifest says: java.util.concurrent;resolution:=optional, I wonder when it becomes non-optional. Personally, I'd say breaking java.io.File would be enough to make it mandatory. Regards, Mark. In message <20100705030517.1f5722388...@eris.apache.org>, regi...@apache.org writes: > > Author: regisxu > Date: Mon Jul 5 03:05:16 2010 > New Revision: 960424 > > URL: http://svn.apache.org/viewvc?rev=960424&view=rev > Log: > make File.createTempFile thread-safe to avoid to return the same file multipl > e times > > File.counter could be accessed by multiple threads, so use AtomicInteger to m > ake > sure each thread using different int value to create temp file. > > Modified: > harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/F > ile.java > > Modified: harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/jav > a/io/File.java > URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/module > s/luni/src/main/java/java/io/File.java?rev=960424&r1=960423&r2=960424&view=di > ff > ============================================================================= > = > --- harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/F > ile.java (original) > +++ harmony/enhanced/java/trunk/classlib/modules/luni/src/main/java/java/io/F > ile.java Mon Jul 5 03:05:16 2010 > @@ -24,6 +24,7 @@ import java.security.AccessController; > import java.security.SecureRandom; > import java.util.ArrayList; > import java.util.List; > +import java.util.concurrent.atomic.AtomicInteger; > > import org.apache.harmony.luni.internal.io.FileCanonPathCache; > import org.apache.harmony.luni.util.DeleteOnExit; > @@ -79,7 +80,7 @@ public class File implements Serializabl > public static final String pathSeparator; > > /* Temp file counter */ > - private static int counter; > + private static AtomicInteger counter = new AtomicInteger(0); > > private static boolean caseSensitive; > > @@ -1300,13 +1301,13 @@ public class File implements Serializabl > } > > private static File genTempFile(String prefix, String suffix, File direc > tory) { > - if (counter == 0) { > + if (counter.get() == 0) { > int newInt = new SecureRandom().nextInt(); > - counter = ((newInt / 65535) & 0xFFFF) + 0x2710; > + counter.compareAndSet(0, ((newInt / 65535) & 0xFFFF) + 0x2710); > } > StringBuilder newName = new StringBuilder(); > newName.append(prefix); > - newName.append(counter++); > + newName.append(counter.getAndIncrement()); > newName.append(suffix); > return new File(directory, newName.toString()); > } >