title: CPU ussage goes 100% while running Java Program
body: <p>My java program requires too much memory. When I run my program, after some time CPU usage goes to 100 % and programs and system halts. What I have tried is "Increase the java heap size but it's not help".</p>
  
  <p>If anyone know what is going wrong please help me.</p>
  
  <p>Here is my code which I am running(It's a Part of speech trainer which trains by brown corpus)</p>
  
  <pre><code>public void readBrownCorpus(String corpusPath) throws IOException {
      BufferedReader inputStream = null;
      try {
          inputStream = new BufferedReader(new FileReader(corpusPath));
          String corpusData = inputStream.readLine();
          String previousTag = "^";
          String wordWithTag[] = corpusData.split(" ");
          for (int i = 0; i &lt; wordWithTag.length; i++) {
              String word[] = wordWithTag[i].split("_");
              if (word != null &amp;&amp; word.length != 2)
                  throw new Exception("Error in the Format of Corpus");
              // If new tag found,insert this in both transitionTable and
              // emissionTable
              if (transitionTable.get(word[1]) == null) {
                  insertTagInTransitionTable(word[1]);
                  insertTagInEmissionTable(word[1]);
              }
              if (emissionTable.get(word[0]) == null) {
                  insertWordinEmissionTable(word[0]);
              }
  
              updateTranstionTable(previousTag, word[1]);
              updateEmissionTable(word[0], word[1]);
              if (word[1].equals(".")) {
                  previousTag = "^";
              } else {
                  previousTag = word[1];
              }
              System.out.println(transitionTable.size());
          }
      } catch (IOException ioException) {
          ioException.printStackTrace();
      } catch (Exception exception) {
          exception.printStackTrace();
      } finally {
          if (inputStream != null)
              inputStream.close();
      }
  }
  </code></pre>
  
  <p>Here is the another function</p>
  
  <pre><code>// This is used to insert the newly found tag in the transition table
      private void insertTagInTransitionTable(String tag) throws CloneNotSupportedException
      {
          for(String key : transitionTable.keySet())
          {
              Row row=transitionTable.get(key);
              row.tagCount.put(tag, 0f);
          }
              // get a row from transition table
              Row newRow = (Row)transitionTable.get("^").Clone();
              for(String key: newRow.tagCount.keySet())
              {
                  newRow.tagCount.put(key,0f);
              }
              transitionTable.put(tag, newRow);
      }
  
      // This is used to insert the newly found tag in the emissionTable
      private void insertTagInEmissionTable(String tag)
      {
              for(String key : emissionTable.keySet())
              {
                  Row row = emissionTable.get(key);
                  row.tagCount.put(tag, 0f);
              }
      }
  
      // This method insert the word in emission table
      private void insertWordinEmissionTable(String word) throws CloneNotSupportedException
      {
                   // get a row from emission table
                      Row newRow = (Row)emissionTable.get("#c1").Clone();
                      for(String key: newRow.tagCount.keySet())
                      {
                          newRow.tagCount.put(key,0f);
                      }
                      emissionTable.put(word, newRow);
      }
  
      // This method is used to update the transitionTable
          private void updateTranstionTable(String previousTag,String currentTag)
          {
              Row row = transitionTable.get(previousTag);
              row.tagCount.put(currentTag, row.tagCount.get(currentTag)+1);
          }
  
          // This method is used to update the emission table
          private void updateEmissionTable(String word,String tag)
          {
              Row row = emissionTable.get(word);
              row.tagCount.put(tag, row.tagCount.get(tag)+1);
          }
  </code></pre>