Ignore:
Timestamp:
2016-11-10T16:09:55+13:00 (7 years ago)
Author:
davidb
Message:

Shift to newIstance for FileSystem due to StackOverflow page describing how the class returned is shared. memory_usage() method added. Removal of some commented out code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • other-projects/hathitrust/wcsa/extracted-features-solr/trunk/solr-ingest/src/main/java/org/hathitrust/extractedfeatures/ClusterFileIO.java

    r30996 r31088  
    2424public class ClusterFileIO {
    2525
    26     private static FileSystem __fs = null;
    27    
    28     /*
    29     public static void initOLD(JavaSparkContext java_spark_context)
     26
     27    public static void memory_usage(String prefix)
    3028    {
    31         try {
    32             Configuration hadoop_conf = java_spark_context.hadoopConfiguration();
    33             _fs = FileSystem.get(hadoop_conf);
    34         }
    35         catch (IOException e) {
    36             e.printStackTrace();
    37         }
     29        Runtime runtime = Runtime.getRuntime();
     30       
     31        java.text.NumberFormat format = java.text.NumberFormat.getInstance();
     32       
     33        StringBuilder sb = new StringBuilder();
     34        long maxMemory = runtime.maxMemory();
     35        long allocatedMemory = runtime.totalMemory();
     36        long freeMemory = runtime.freeMemory();
     37       
     38        sb.append(prefix+" free memory: " + format.format(freeMemory / 1024) + "\n");
     39        sb.append(prefix+" allocated memory: " + format.format(allocatedMemory / 1024) + "\n");
     40        sb.append(prefix+" max memory: " + format.format(maxMemory / 1024) + "\n");
     41        sb.append(prefix+" total free memory: " + format.format((freeMemory + (maxMemory - allocatedMemory)) / 1024) + "\n");
     42
     43        System.out.print(sb.toString());
    3844    }
    39     */
    40    
    41     /*
    42     public static void init(String input_dir)
    43     {
    44         try {
    45             Configuration conf = new Configuration();
    46             URI uri = new URI(input_dir);
    47             _fs = FileSystem.get(uri, conf);
    48         }
    49         catch (URISyntaxException e) {
    50             e.printStackTrace();   
    51         }
    52         catch (IOException e) {
    53             e.printStackTrace();
    54         }
    55        
    56     }
    57     */
     45
    5846   
    5947    protected static FileSystem getFileSystemInstance(String input_dir)
    6048    {
    61         if (__fs == null) {
     49        FileSystem fs = null;
    6250
    63             try {
    64                 Configuration conf = new Configuration();
    65                 URI uri = new URI(input_dir);
    66                 __fs = FileSystem.get(uri, conf);
    67             }
    68             catch (URISyntaxException e) {
    69                 e.printStackTrace();   
    70             }
    71             catch (IOException e) {
    72                 e.printStackTrace();
    73             }
    74         }
    75         return __fs;
     51        try {
     52        Configuration conf = new Configuration();
     53        URI uri = new URI(input_dir);
     54        fs = FileSystem.newInstance(uri,conf);
     55        }
     56        catch (URISyntaxException e) {
     57        e.printStackTrace();   
     58        }
     59        catch (IOException e) {
     60        e.printStackTrace();
     61        }
     62
     63        return fs;
    7664    }
    7765   
Note: See TracChangeset for help on using the changeset viewer.