저는 현재 실행중인 Bodi 서버가 있으며 일정보다 앞서 함수가 종료되는 것처럼 특정 줄에서 종료합니다. 나는이 문제를 Eclipse와 NetBeans에 시도한 후 여기에서 그 원인을 프로그래밍 방식으로 가정한다. 부모 스레드는 checkinputqueue() 및 checkoutputqueue()를 폴링하고 이들이 차례로 처리 할 준비가되었다고 플래그하는 서버의 데이터가 있는지 확인합니다.스레드가 조기에 종료합니다.
Bodi 서버는 공유 개체 서버입니다. 로컬 JVM에 객체를 요청하고이를 정적 참조와 비슷하게 만들거나 원격으로 다른 JVM에 객체를 요청할 수 있으며 객체 참조를 가져올 수 있습니다.
작동하지 않습니다. 너희들도 도와 줄 수 있니? 주요 문제는 readLine() 메서드가 종료되기 전에 종료되는 스레드입니다. readLine()에 대한 호출은 추적 할 실행이 더 이상없는 것처럼 디버거 세션을 종료합니다.
/*
* 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 apml.system.bodi.remote;
/**
*
* @author Max Rupplin
*/
class Listenerthread extends Thread
{
public volatile Connection connection;
public Boolean running = true;
//public Basicserver server;
public volatile Inputlistenerthread inputlistenerthrread;
public volatile Outputlistenerthread outputlistenerthread;
public Listenerthread(Connection connection)
{
this.connection = connection;
/*---------------------------------------------------------------------*/
this.setName("Listenerthread");
/*---------------------------------------------------------------------*/
this.inputlistenerthrread = new Inputlistenerthread(this);
this.inputlistenerthrread.start();
/*---------------------------------------------------------------------*/
this.outputlistenerthread = new Outputlistenerthread(this);
this.outputlistenerthread.start();
}
@Override
public void run()
{
System.out.println("> Server main thread started...");
while(running)
{
System.err.println("Listner thread now looping...");
try
{
synchronized(this.inputlistenerthrread.lock)
{
if(this.inputlistenerthrread.hasreadready)
{
this.inputlistenerthrread.checkinputqueue();
this.connection.isdonereading = true;
}
}
synchronized(this.outputlistenerthread.lock)
{
if(this.outputlistenerthread.haswriteready)
{
this.outputlistenerthread.checkoutputqueue();
this.connection.isdonewriting = true;
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
try
{
Thread.sleep(400);
}
catch(InterruptedException ie)
{
running = false;
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
System.out.println("Basicserver listener thread exiting...");
}
}
/----/
package apml.system.bodi.remote;
/**
*
* @author Max Rupplin
*/
class Inputlistenerthread extends Thread
{
public Boolean hasreadready = false;
public Boolean isnotchecking = true;
public Boolean running = true;
public volatile Listenerthread parent;
public volatile Object lock = new Object();
public Inputlistenerthread(Listenerthread parent)
{
this.parent = parent;
this.setName("Inputlistenerthread");
}
public Boolean checkinputqueue()
{
synchronized(this.lock)
{
StringBuffer inputbuffer = new StringBuffer();
try
{
//this.lock.wait();
String line = null;
while((line = this.parent.connection.reader.readLine()) != null)
{
inputbuffer.append(line);
this.parent.connection.isdonereading = false;
}
if(inputbuffer.toString().length()>0)
{
this.parent.connection.inqueue.append(inputbuffer);
this.parent.connection.server.inputqueue.add(this.parent.connection);
this.parent.connection.hasreadready = true;
this.parent.connection.isdonereading = true;
}
}
catch(Error e)
{
e.printStackTrace();
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
inputbuffer = null;
//this.lock.notifyAll();
}
return true;
}
}
@Override
public void run()
{
System.out.println("> Inputlistenerthread started...");
try
{
while(running)
{
try
{
//if(this.parent.server.reader.lines().count()>0 || true)
if(true)
{
this.hasreadready = true;
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally
{
Thread.currentThread().sleep(250);
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
'lock.wait()'줄을 주석 처리했기 때문에, read가 null이어서 종료 할 수 있다는 것을 의미하지는 않습니까? – didiz
디버그 모드에서는 if (inputbuffer.toString(). length()> 0) 행을 건너 뛸 수 있으므로이 스레드의 실행을 올바르게 실행하지 않는다고 가정했습니다. –
대기열에서 처리 할 수있을 때까지 기다리는 줄입니다. 그렇지 않으면 대기열이 비어 있으므로 아무것도 수행하지 않아 종료됩니다. – didiz