Github user otaviojava commented on a diff in the pull request:

    https://github.com/apache/tomee/pull/262#discussion_r240188979
  
    --- Diff: 
container/openejb-loader/src/main/java/org/apache/openejb/loader/FileUtils.java 
---
    @@ -20,18 +20,25 @@
     import java.io.FileNotFoundException;
     import java.io.IOException;
     import java.util.Hashtable;
    +import java.util.concurrent.ThreadLocalRandom;
     
     @SuppressWarnings("PMD.OverrideBothEqualsAndHashcode")
     public class FileUtils {
     
    -    private static final java.util.Random _random = new java.util.Random();
    +    private static final ThreadLocalRandom _random = 
ThreadLocalRandom.current();
    --- End diff --
    
    hey, what David means is instead of having the field, just use it every 
time.
    
    E.g:
    
    ```java
    public class FileUtils {
    
    //not more the static field
    
        private File home;
    
        private FileUtils(final String homeDir, final String defaultDir) {
            this(homeDir, defaultDir, SystemInstance.get().getProperties());
        }
    
     public static File createTempDirectory(final String pathPrefix) throws 
IOException {
            for (int maxAttempts = 100; maxAttempts > 0; --maxAttempts) {
    
                final String path = pathPrefix + 
ThreadLocalRandom.current().nextLong();
                final File tmpDir = new File(path);
    
                if (!tmpDir.exists() && tmpDir.mkdirs()) {
                    return tmpDir;
                }
            }
            throw new IOException("Cannot create temporary directory at: " + 
pathPrefix);
        }
    ```


---

Reply via email to