Now you are confusing me! You said the send to queue was not working, but the message you got is only printed after the send to queue.
I don't know where or how you are using the isAlive, or even which thread that is on.
Maybe the problem is in the thread where your Commserver main method executes (the one where it waits for inbound connections, the only one you don#t start explicitly) rather than any one ConnectionHandler thread.

Dear James,
Sorry if I confused you. Below is the updated codes. You can see where I put the isAlive too. Next this is what I can see when it failed yesterday after adding the isAlive.

Basically this how the sequence of normal message should be printed.

Only Available in connection handler
System.out.println("\n\nSending TO QUEUE : "+message);
System.out.println("\n\n DatabaseProcessor.isAlive : "+message);
System.out.println("\n\nSent TO QUEUE : "+message);

Only Available in database processor
System.out.println("\n\nPICKED AT QUEUE : "+message);
System.out.println("\n\n1St PICK QUEUE : "+message);
System.out.println("\n\n2nd PICK QUEUE : "+message);
System.out.println("\n\n3rd PICK QUEUE : "+message);
System.out.println("\n\nREACHED TO WRITE FILE:"+message);
System.out.println("\n\nLAST PART OF WRITING TO FILE:"+message);
System.out.println("\n\n4th PICK QUEUE : "+message);

Below are the messages printed immediately when it failed for few minutes

Only Available in connection handler
System.out.println("\n\nSending TO QUEUE : "+message);
System.out.println("\n\n DatabaseProcessor.isAlive : "+message);
System.out.println("\n\nSent TO QUEUE : "+message);

Thereafter it print only but not DatabaseProcessor.isAlive

Only Available in connection handler
System.out.println("\n\nSending TO QUEUE : "+message);
System.out.println("\n\nSent TO QUEUE : "+message);

public class commServer {
   private LinkedBlockingQueue<String> databaseQueue = new LinkedBlockingQueue<String>();
   private LinkedBlockingQueue<String> eMailQueue = new LinkedBlockingQueue<String>();
 
   Thread t1;
   Thread c1;
 
   class ConnectionHandler implements Runnable {
 
    private Socket receivedSocketConn1;
    ConnectionHandler(Socket receivedSocketConn1) {
      this.receivedSocketConn1=receivedSocketConn1;
    }
 
 
      // gets data from an inbound connection and queues it for databse update
 
      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;  
		           	   //n = n + (char) m;
		           	  //  n = new StringBuffer().append((char)m).toString();
		         	  int i = message.indexOf("GET");
								if(i != -1) { 
									break;
								}
 
		         	  if (nextChar == '#')
		         	  {
			             System.out.println("\n\nSending PA : "+message);
			             w.write("$PA\r\n");
		                 w.flush(); 
		                 System.out.println("\n\nSending TO QUEUE : "+message);
		                 if(t1.isAlive()) {
		                 	System.out.println("\n\n DatabaseProcessor.isAlive : "+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 ");
 
		         System.out.println("\n\nDevice Closed The Connection Properly");
		      } 
		      catch (Exception ex)  
		      { 
		           System.out.println( "\n\n\n THE device had exception problem"+" "+ receivedSocketConn1.getInetAddress() +":"+receivedSocketConn1.getPort()+" IS CONNECTED ");
 
		           System.out.println("MyError:Exception has been caught in in the main first try");
		           ex.printStackTrace(System.out);
		      }      
		      finally
		      {
		        try 
		       	{
		            System.out.println( "\n\n\n THE device is in finally"+" "+ receivedSocketConn1.getInetAddress() +":"+receivedSocketConn1.getPort()+" IS CONNECTED ");
 
		            if ( w != null ) 
			        {
			          	w.close();
			        }
			        else 
			        {
			        	System.out.println("MyError:w is null in finally close");
			        }
		        }
		        catch(IOException ex){
		           System.out.println("MyError:IOException has been caught in w in finally close");
		           ex.printStackTrace(System.out);
		        }
 
		      }
 
      }
 
   }
 
 
 
   class DatabaseProcessor implements Runnable {
 
   }
 
   public static void main(String[] args) {
 
      // It's bad O.O. practice to put all your code in static main method.
 
      // Create a new instance of the class, and put the code there
 
      new commServer();
 
   }
 
 
 
   commServer() { // default constructor
 
      //t1 = new Thread(new DatabaseProcessor()).start();
      t1 = new Thread(new DatabaseProcessor());
      t1.start();
 
      new Thread(new MailProcessor()).start();
 
      try 
      {
			   final ServerSocket serverSocketConn = new ServerSocket(9000);				
			   while (true) 
					{
						try 
						{
					            Socket socketConn1 = serverSocketConn.accept();
                                c1 = new Thread(new ConnectionHandler(socketConn1));					            c1.setPriority(Thread.MAX_PRIORITY);
					            c1.start();			            
						}
						catch(Exception e)
						{
							System.out.println("MyError:Socket Accepting has been caught in main loop."+e.toString());
						    e.printStackTrace(System.out);
						}
					}
      } 
      catch (Exception e) 
      {
         System.out.println("MyError:Socket Conn has been caught in main loop."+e.toString());
         e.printStackTrace(System.out);
         //System.exit(0); 
      }
      databaseQueue.add(null);
 
      eMailQueue.add(null);
 
   }

Dear James,
Did I put my isAlive correctly? Another question is it possible due to some resultset not closed properly can this be the cause of this funny problem?

The info you give is so vague that I really don't know how to answer. Just keep adding print statements until you can pinpoint the exact place where it's failing.

Dear James,
I google and I got a big problem here cause I did not completely close all the resultset and statments. So could that be a one of the contributing factor here?

Dear James,
It keep fail there where I wont see the databaseprocessor thread alive. So what possible is the reason can be due to the resultset and statement?

Listen, I honestly don't know. I don't have your database code, nor your database to test against, nor am I the best person here to do SQL stuff because that's not my specialty. So sorry, but I can't help you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.