100% da CPU

Galera estou precisando de ajuda, sempre que eu inicio meu programa em java ele usa 100% da CPU.
Nao faco ideia de como resolver isso alguém pode me ajudar???

Sem saber o que seu programa faz, nós também não sabemos o que recomendar. Há algum processamento sendo executado quando o programa inicia? Tente comentar quaisquer loops, consultas ao banco, etc. até descobrir o que pode estar acontecendo.

Abraço.

Script 1: Muitos Loops
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package d.i.n.o.java;

import java.util.ArrayList;

/**
 *
 * @author Matheus
 */
public class MachineLearning extends Thread{
    
    public static Boolean Read;
    public static String[] ReceivedSeparator;
    public static String[] DataSeparator;
    public static boolean Pross; 
    
    public static boolean teach;
    public static String TeachTxt;
    public static ArrayList<String> Understand = new ArrayList<String> ();
    public static int Index;
    
    public static int Probability;
    public static int MaxPrints;
    
    public static String Confirm;
    public static int TeachConfirm;
    public static int Faze;
    public static int a;
    
    public static boolean TeachPross;
    public static String TeachTxtFaze1;
    
    public static ArrayList<String> ReadPross = new ArrayList<String> ();
    public static ArrayList<String> ReadNLP = new ArrayList<String> ();
    
    public void run(){
        
        while (true) {            
            
    if(Pross == true){
        
    Read = false;
    
    
    ReceivedSeparator = Server.Received.split(" ");
    
    for(int x = 0; ReceivedSeparator.length > x;x++){
        
        
        for(int z = 0;DataCenter.Keyword.size() > z;z++){
            
            if(ReceivedSeparator[x].equals(DataCenter.Keyword.get(z))){
            
                Probability += 100;
                
            }
            
            }
            
        if(Probability < 100){
            Understand.add(ReceivedSeparator[x]);
        }else{
            
            ReadPross.add(ReceivedSeparator[x]);
            
        }
        
        }

    Pross = false;
     }else{//IF
    Read = true;
    }
    
    //Machine Learning
    
    if(!Understand.isEmpty()){
        
        ReadPross.clear();
        
        if(TeachConfirm == 0){
        
        if(MaxPrints == 0){
        System.out.println("DINO: Tenho algumas duvidas,voce pode me ensinar?");
        System.out.println("");
        System.out.println("Duvidas: ");
        
        for(int f = 0;Understand.size() > f;f++){
           System.out.println(f+": "+Understand.get(f)); 
        }
            System.out.println("");
        System.out.println("SISTEMA: Digite 'N' para nao | 'S' para sim (Em Maiusculo)");
        
        MaxPrints += 1;
        }
        
        if(Confirm != null){
            
        if(Confirm.equals("N")){
            System.out.println("DINO: Ok entao");
            System.out.println("");
            Confirm = null;
            MaxPrints = 0;
            Understand.clear();
        }else{
            teach = true;
            Confirm = null;
            MaxPrints = 0;
            TeachConfirm += 1;
        }
        
        }
     
        }else{
            teach = true;
        }
        
            if(teach == true){
        
        if(MaxPrints == 0){
            
       System.out.println("");     
       System.out.println("DINO: Oque e isso: "+Understand.get(Index));
       
       System.out.println("SISTEMA: Classifique em: Palavra | Objeto | Acao | Nome  (Nao ignore as letras maiusculas e nao use assentos!)");
       
       Faze = 1;
       
       MaxPrints += 1;
        }
               
        if(GUI.Click == true){
            
           TeachTxt = GUI.Field.getText();
           GUI.Field.setText("");
               
                DataCenter.Keyword.add(Understand.get(Index));
                
                if(TeachTxt != null){
                    
                if(Faze == 1){
                    if(TeachTxt.equals("Palavra")){
                       DataCenter.Word.add(Understand.get(Index));
                       Faze = 2;
                    }
                      if(TeachTxt.equals("Objeto")){
                       DataCenter.Object.add(Understand.get(Index));
                       Faze = 2;
                    }
                        if(TeachTxt.equals("Acao")){
                       DataCenter.Action.add(Understand.get(Index));
                       Faze = 2;
                    }
                          if(TeachTxt.equals("Nome")){
                       DataCenter.PersonName.add(Understand.get(Index));
                       Faze = 2;
                    }
                          
                   System.out.println("VOCE: "+TeachTxt);
                   TeachTxtFaze1 = TeachTxt;
                   TeachTxt = "";
                   
                }
                
                if(Faze == 2){
                    
                    if(TeachTxtFaze1.equals("Palavra")){
                        
                        System.out.println("");
                        System.out.println("SISTEMA: Classifique a palavra em: Sujeito | Negacao | Afirmacao | Interjeicao (Nao ignore as letras maiusculas e nao use assentos!)");
                       
                        if(TeachTxt.equals("Sujeito")){
                           
                           DataCenter.Subject.add(Understand.get(Index));
                           System.out.println("VOCE: "+TeachTxt);
                           Faze = 10;
                       }
                       
                       if(TeachTxt.equals("Negacao")){
                           
                           DataCenter.Negative.add(Understand.get(Index));
                           System.out.println("VOCE: "+TeachTxt);
                           Faze = 10;
                       }
                       
                       if(TeachTxt.equals("Afirmacao")){
                           
                           DataCenter.Affirmative.add(Understand.get(Index));
                           System.out.println("VOCE: "+TeachTxt);
                           Faze = 10;
                       }
                       
                       if(TeachTxt.equals("Interjeicao")){
                           
                           DataCenter.Interjections.add(Understand.get(Index));
                           System.out.println("VOCE: "+TeachTxt);
                           Faze = 10;
                       }
                       
                    }
                    
                     if(TeachTxtFaze1.equals("Objeto")){
                         
                         System.out.println("SISTEMA: De uma definicao para esse objeto (Mais de 10 letras)");
                         
                       if(TeachTxt.length() > 1){
                           
                       DataCenter.Definicion.add(TeachTxt);
                       Faze = 10;
                       System.out.println("VOCE: "+TeachTxt);
                       
                       }
                       
                     }
                     
                      if(TeachTxtFaze1.equals("Acao")){
                          
                         System.out.println("SISTEMA: De uma definicao para esse acao (Mais de 10 letras)");
                         
                       if(TeachTxt.length() > 1){
                           
                       DataCenter.Definicion.add(TeachTxt);
                       Faze = 10;
                       System.out.println("VOCE: "+TeachTxt);
                       
                       }
                       
                      }
                       if(TeachTxtFaze1.equals("Nome")){   
                           
                         System.out.println("SISTEMA: De uma definicao para esse nome (Mais de 10 letras)");
                         
                       if(TeachTxt.length() > 1){
                           
                       DataCenter.Definicion.add(TeachTxt);
                       Faze = 10;
                       System.out.println("VOCE: "+TeachTxt);
                       
                       }
                       
                     }
                }          
                               
                if(Faze == 10){
                Faze = 0;
                a = Understand.size() - 1;
                MaxPrints = 0;
                TeachTxt = "";   
                TeachPross = true;
                }
                
                if(TeachPross == true){
                if(Index < a){
                   Index += 1;
                   TeachPross = false;
                }else{
                    Index = 0;
                    Understand.clear();
                    teach = false;
                    TeachConfirm = 0;
                    
                    System.out.println("");
                    System.out.println("DINO: Obrigado por me ensinar!!!");
                    System.out.println("");
                    TeachPross = false;
                }
                }
                
                }
                
        GUI.Click = false;
        }
        
    }

    }else{
        ReadNLP = ReadPross;
    }
            
        }//While
        
    }//Run
    
}//Class

Script 2: muitos for

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package d.i.n.o.java;

import static d.i.n.o.java.MachineLearning.ReadNLP;
import java.util.Random;

/**
 *
 * @author Matheus
 */
public class NLP extends Thread{
    
    String Answer;
    Random randomGenerator = new Random ();
    int Index;
    
    public void run(){
        
        while (true) {            
            
            if(!ReadNLP.isEmpty()){
                
             for(int i = 0;ReadNLP.size() > i;i++){
                 
                 for(int a = 0;DataCenter.Word.size() > a;a++){
                     
                     if(ReadNLP.get(i).equals(DataCenter.Word.get(a))){
                         
                         for(int e = 0;DataCenter.Interjections.size() > e;e++){
                             if(ReadNLP.get(i).equals(DataCenter.Interjections.get(e))){
                                 
                                 int randomInt = randomGenerator.nextInt ( DataCenter.Interjections.size() );
                                 if(Answer == null){
                                 Answer = DataCenter.Interjections.get(randomInt);
                                 }else{
                                    Answer = Answer + DataCenter.Interjections.get(randomInt); 
                                 }
                                     
                             }
                         }
                         for(int e = 0;DataCenter.Affirmative.size() > e;e++){
                             if(ReadNLP.get(i).equals(DataCenter.Affirmative.get(e))){
                                 
                             }
                         }
                         for(int e = 0;DataCenter.Negative.size() > e;e++){
                             if(ReadNLP.get(i).equals(DataCenter.Negative.get(e))){
                                 
                             }                            
                         }
                         for(int e = 0;DataCenter.Subject.size() > e;e++){
                             if(ReadNLP.get(i).equals(DataCenter.Subject.get(e))){

                             }
                         }
                     
                 }
                 for(int b = 0;DataCenter.Action.size() > b;b++){
                     
                    if(ReadNLP.get(i).equals(DataCenter.Action.get(b))){
                         
                     } 
                     
                 }
                 for(int c = 0;DataCenter.Object.size() > c;c++){
                     
                   if(ReadNLP.get(i).equals(DataCenter.Object.get(c))){
                         
                     }   
                     
                 }
                 for(int d = 0;DataCenter.PersonName.size() > d;d++){
                     
                     if(ReadNLP.get(i).equals(DataCenter.PersonName.get(d))){
                         
                     } 
                     
                 }
                 
             }
                Index = i;
            }
             
                if(Index == ReadNLP.size()){
                System.out.println("DINO: "+Answer);
                Index = 0;
                ReadNLP.clear();
                }

            }
             
        }//While
        
    }//Run
    
}//Class

Deve estar fritando o processador com esse while true. Pelo menos dê um refresco pro processador:

while (true) {
   ....
   Seu código
   ....
   Thread.sleep(5000);
}

Te passei a forma mais fácil e preguiçosa. O mais recomendado é usar wait e notifyAll. Exemplo: https://www.qat.com/using-waitnotify-instead-thread-sleep-java/

3 curtidas

vlw mano.
Feliz Natal