title: Difficulty understanding thread logic - assigning variables
body: <p>I am reading in two separate text files with two separate threads, and trying to then assign them to to separate HashMaps, and implementing the Runnable interface. The run method calls the file parser method, and assigns it to a class variable - hashMap. How would I go about assigning the separate threads to new HashMap variables? I feel there is a fundamental flaw in my class design.. but any help would be much appreciated.</p>
  <p>Edit</p>
  <pre><code>public void run(){
  this.hashMapSubject = getMap(this.text);
      this.hashMapQuery = getMap(this.text); //This just causes an overwrite of data ^^
  </code></pre>
  <p>}</p>
  <pre><code>public class RunnerClass {
  
  public static void main(String[] args)  {
      Menu m = new Menu();
      m.start(); //gets user input and assigns to user subject, and then userQuery string variables.
  
      Thread t1 = new Thread(new Parser(m.getUserSubject()), &quot;UserSubject&quot;);
      Thread t2 = new Thread(new Parser(m.getUserQuery()), &quot;UserQuery&quot;);
      t1.start();
      t2.start();     
      
  }
  </code></pre>
  <p>Here is my parser class</p>
  <pre><code>public class Parser implements Runnable {
  private Map&lt;Integer, Integer&gt; hashMap;
  private String line = &quot;&quot;;
  private BufferedReader br;
  private Map&lt;Integer, Integer&gt; hashMapSubject; //****** Need to assign one to this variable
  private Map&lt;Integer, Integer&gt; hashMapQuery; //***** Need to assign one to this variable
  private String text;
  
  public Parser(String text) { //new Thread passes user value to constructor parameter
      this.text = text;
  }
  public Map&lt;Integer, Integer&gt; getMap(String text) {
  
      this.hashMap = new HashMap&lt;&gt;();
      try {
          br = new BufferedReader(new InputStreamReader(new FileInputStream(this.text)));
                      
          while ((line = br.readLine()) != null) {
              line.toLowerCase().replaceAll(&quot;,&quot;, &quot;&quot;);
              String[] words = line.split(&quot;(?&lt;=\\G.....)&quot;);
              
              System.out.println(Thread.currentThread().getName());
  
              for (String word : words) {
                  int hash = word.hashCode();
                  int frequency = 1;
                  if (hashMap.containsKey(hash)) {
                      frequency += hashMap.get(hash);
                  }
                  hashMap.put(hash, frequency);
                  
              }           
          }           
      }
           catch (IOException e) {
          System.out.println(&quot;File not found&quot;);
          e.printStackTrace();
      }
  
      return hashMap;
  }
  @Override //**************************************
  public void run() {
      getMap(this.text);
  
      //********************************************
  } //run method here getsMap() for each thread 
  </code></pre>
  <p>}</p>
  <p>An example of the output: I see both threads are executing their tasks but I am stumped on how to extract the data into new variables</p>
  <pre><code>Enter subject...
  Enter Query...
  Processing...
  UserSubject
  UserQuery
  UserSubject
  UserQuery 
  UserSubject //continues like this until termination
  </code></pre>