2014-09-18 3 views
0

스트레스 테스트를위한 응용 프로그램을 만들고 있습니다. 이를 1500 번 수행하고 피고용자의 내부 네트워크를 통해 동시에 1500 개의 스레드를 연결합니다. 1500 턴은 스레드라고 불리며, 소켓은 소켓을 닫을 때 소켓을 호출하고 다시 열리고 동일한 데이터를 다시 보냅니다. 문제는 응용 프로그램이 무한 루프가 있고 stackoverflows가 발생한다고 말하는 오류가 발생하지만 Java 재귀 호출을 만드는 것이지만 생각을 떠나지는 않습니다. 내가 할 수있는 것?java.lang.OutOfMemoryError in recursive threads

Main 클래스 :

public void startStres(){ 

    for(int n = 1; n <= Integer.parseInt(valueThreads.getText().toString()); n++) 
     robots.add(new robot(this, n, valueUrl.getText().toString())); 

    valueTotal.setText(Integer.toString(robots.size())); 

    for(final robot bot : robots) 
     new Thread(new Runnable() { 
      public void run() { 
       bot.start(); 
      } 
     }).start(); 
} 

로봇 클래스에서 :

public void start(){ 
     context.robotOnConnecting(idUnique); 

     try { 
      socketHandle = new Socket(InetAddress.getByName(dataConnection.host), dataConnection.port); 
      context.robotOnConnect(idUnique); 

      PrintWriter writer = new PrintWriter(socketHandle.getOutputStream()); 
      writer.print(
       "GET " + dataConnection.query + " HTTP/1.1\n" + 
       "Host: " + dataConnection.host + "\n" + 
       "User-Agent: " + dataConnection.userAgent + "\n" + 
       "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\n" + 
       "Accept-Language: en-US,en;q=0.5\n" + 
       "Accept-Encoding: gzip, deflate\n" + 
       "Connection: keep-alive\n\n" 
      ); 
      writer.flush(); 

      BufferedReader br = new BufferedReader(new InputStreamReader(socketHandle.getInputStream())); 

      char[] bt = new char[1]; 
      br.read(bt, 0, 1); 
      br.close(); 
      socketHandle.close(); 

      context.robotOnFinish(idUnique); 
      context.robotOnClose(this, idUnique, true); 
      //start(); <-- Error 

     } catch (IOException e) { 
      context.robotOnError(idUnique, e.getMessage()); 
      context.robotOnClose(this, idUnique, false); 

      //start(); <-- Error 
      // e.printStackTrace(); 
     } 
    } 

오류 : 간단하게

526-1073/com.x.audits.strestesting D/dalvikvm﹕ GC_FOR_ALLOC freed 16K, 21% free 50827K/63572K, paused 41ms, total 41ms 
526-1095/com.x.audits.strestesting I/dalvikvm﹕ threadid=25: stack overflow on call to Ljava/lang/ThreadLocal;.get:L 
526-1095/com.x.audits.strestesting I/dalvikvm﹕ method requires 28+20+8=56 bytes, fp is 0x761f9314 (20 left) 
526-1095/com.x.audits.strestesting I/dalvikvm﹕ expanding stack end (0x761f9300 to 0x761f9000) 
526-1095/com.x.audits.strestesting I/dalvikvm﹕ Shrank stack (to 0x761f9300, curFrame is 0x761f9488) 
526-1089/com.x.audits.strestesting I/dalvikvm﹕ threadid=19: stack overflow on call to Ljava/lang/ThreadLocal;.get:L 
526-1089/com.x.audits.strestesting I/dalvikvm﹕ method requires 28+20+8=56 bytes, fp is 0x76189314 (20 left) 
526-1089/com.x.audits.strestesting I/dalvikvm﹕ expanding stack end (0x76189300 to 0x76189000) 
526-1089/com.x.audits.strestesting I/dalvikvm﹕ Shrank stack (to 0x76189300, curFrame is 0x76189488) 
526-1089/com.x.audits.strestesting W/dalvikvm﹕ threadid=19: thread exiting with uncaught exception (group=0x418a8898) 
526-1095/com.x.audits.strestesting W/dalvikvm﹕ threadid=25: thread exiting with uncaught exception (group=0x418a8898) 
+0

스택 오버플로? – Unihedron

답변

1

멀티 스레딩을 처리 할 때는 이러한 종류의 문제를 피하기 위해 스레드 풀을 사용해야합니다.

체크 아웃 ThreadPoolExecutor.execute(Runnable). 멀티 스레딩을보다 잘 처리 할 수 ​​있습니다.

+0

이것은 덧글 –

+0

이어야한다. 그것에 대해 자세히 알아 보겠다. –

+0

완전히 내 문제를 해결했습니다. 이 클래스는 내 컴퓨터 하드웨어, 코어 수 등을 처리 할 수 ​​있으며 모든 작업을 원활하게 해줍니다. –

1

:

public void start() { 
    while(true) { 
     doWork(); 
    } 
} 

private void doWork() { 
    // do all the work non recursively 
} 
+0

작동하지만 지난 30 초 동안 동일한 문제가 발생하고 동일한 로그가 닫히고 표시됩니다. –

+0

다시 Stackoverflow ?? –

+0

I/dalvikvm-heap : 16400 바이트 할당에 대한 SoftReference 수집 강제 실행 D/dalvikvm : GC_BEFORE_OOM 해제 된 0KB, 19 % 무료 106799K/131064K, 일시 중지 된 175ms, 총 175ms E/dalvikvm-heap : 16400의 메모리 부족 바이트 할당. –