-1
データの読み取りを継続するソケット接続があり、次に別のスレッドで次の処理のためにキューを介して送信します。私は時々キューにデータを送ることを止めることに気づきます。私はこのSystem.out.printlnを印刷します( "\ n \ nキューに送る:" +メッセージ)。停止しますが、エラーをキャプチャする方法をキャプチャしているエラーは表示されません。ここで起こりうるエラーは何か?キューへのデータの送信が機能しない
class ConnectionHandler implements Runnable {
private Socket receivedSocketConn1;
ConnectionHandler(Socket receivedSocketConn1) {
this.receivedSocketConn1=receivedSocketConn1;
}
public void run() {
BufferedWriter w = null;
BufferedReader r = null;
String message="";
try {
PrintStream out = System.out;
BufferedWriter fout = null;
w = new BufferedWriter(new OutputStreamWriter(receivedSocketConn1.getOutputStream()));
r = new BufferedReader(new InputStreamReader(receivedSocketConn1.getInputStream()));
int m = 0, count=0;
int nextChar=0;
System.out.println("\n\n\n THE device"+" "+ receivedSocketConn1.getInetAddress() +":"+receivedSocketConn1.getPort()+" IS CONNECTED ");
while ((nextChar=r.read()) != -1)
{
message += (char) nextChar;
int i = message.indexOf("GET");
if(i != -1) {
break;
}
if (nextChar == '#')
{
w.flush();
System.out.println("\n\nSending TO QUEUE : "+message);
databaseQueue.add(message);
System.out.println("\n\nSent TO QUEUE : "+message);
message="";
}
}
System.out.println("\n\n\n THE device close connection"+" "+ receivedSocketConn1.getInetAddress() +":"+receivedSocketConn1.getPort()+" IS CONNECTED ");
}
catch (Exception ex)
{
ex.printStackTrace(System.out);
}
finally
{
try
{
if (w != null)
{
w.close();
}
}
catch(IOException ex){
ex.printStackTrace(System.out);
}
}
}
}
データベース処理キューのスレッドスニペットコード。
class DatabaseProcessor implements Runnable {
// updates databaase with data queued by ConnectionHandler
Connection dbconn = null;
Statement stmt = null;
Statement stmt1 = null;
Statement stmt2 = null;
Date connCreated = null;
public void run()
{
// this is just like the QueueProcessor example I gave you
// open database connection
createConnection();
while (true)
{
try
{
int count=0;
String message = "";
message = databaseQueue.take();
System.out.println("\n\nPICKED AT QUEUE : "+message);
if (message.equals(null)) {
System.out.println("QueueProcessor is shutting down");
break; // exit while loop, ends run() method
}
//there is more codes but is too long to be put here.
}
}
}
}
'databaseQueue'型は何ですか?いくつかのコードがありません –
@peter databaseQueueは別のスレッドかもしれません。 – user837306
まだデータ型はありませんか?私はそれがConnectionHandlerとDatabaseProcessorの間の共有インスタンスだと仮定します。 –