Error Cleaninjg up Agent Treads

Hi I have a issue .I have a java agent .yesterday, I got this error suddenly “Error Cleaning up Agent threads”.This agent is working fine for Years.

Can this lead to slow down of Server .

Can this be document related .

import lotus.domino.*;

import java.net.*;

import java.io.*;

import java.util.Vector;

public class JavaAgent extends AgentBase {

 static final int MAXBYTE = 153;

int ClientDocCount =0;

 int DocSendCount = 0;

 String theOutput = null;

 String theInput = null;	

 String sign[] = { "S", "Y", "R", "E", "N" };

String serverInput = null;          

 String key = null; 	

String date = null;

String dealercode = null;

 String sequential = null;

 String tranref = null;

 String typecode = null;

 String standardcode = null;

 String bondtypecode = null;

 String bondname = null;

 String inputtime = null;

 String askyieldrate = null;

 String bidyieldrate = null;

 String sellingprice = null;

 String buyingprice = null;

 String sellingvolume = null;

 String buyingvolume = null;

 String issuedate = null;

 String couponrate = null;

 String maturity = null;

 String discountrate = null;

 String retentionperiod = null;

 String rateofreturnaftertax = null;

 String interestpaymentcondition = null;

String classification = null;

 String referdatalist = new String("");     

Dealer client = null; 

int timeDelay = 0;

String YReply = null;

String RReply = null;

String NReply = null;

String bondSend = null;	

String Serverkey = null; 

char status = '\0';

int cnt = 0;   		                            

Document doc = null;

DateTime Date_Time = null;

String sGMTTime = null;

Log errlog = null;

 DateTime stDateTime = null;  

 DateTime crDateTime = null; 

Session session = null;



HttpParser hp = null;

int count = 0;

String connectstatus = null;   



 public void NotesMain() {

	try {

		session = getSession ( );

		AgentContext agentContext = session.getAgentContext ( );

		Database db = agentContext.getCurrentDatabase ( );

		if (db == null) {	

			errlog.openNotesLog("0", "*Database open failed");

		}	

		

		//Get the korian characters..

		String server = db.getServer();

		Name servName = session.createName ( server);

		String url = "http://" + servName.getCommon() + "/" + db.getFilePath().replace('\\', '/')  + "/ViewKSDA?OpenView";

		

		hp = new HttpParser(url);

		if ( !hp.GetCharacters() ) 

			return;

		Date_Time = session.createDateTime("Today");

		errlog = session.createLog("Update to KSDA on " + Date_Time.toJavaDate() );

		errlog.openNotesLog(db.getServer(), db.toString());

		

		View pendingView = db.getView ("lookupKSDAPending");

		//The View should be changed to display only the appropriate status and replace the key lookup with 

		//document iterations..

// DocumentCollection docColl = pendingView.getAllDocumentsByKey(“Pending KSDA Update”,false);

// doc = docColl.getFirstDocument();

		doc = pendingView.getFirstDocument();

		

		if (doc == null) {

			errlog.logAction("*Zero or No Documents found");						

		}

		else {

		     View sysProfileView = db.getView("LookupSystemProfile");

			Document sysProfileDoc = sysProfileView.getFirstDocument();			

			String ip = sysProfileDoc.getItemValueString("IPAddress_x");

							String altip = sysProfileDoc.getItemValueString("AltIPAddress_x");



			int port = sysProfileDoc.getItemValueInteger("PortNo_n") ;				

			int reConnect = sysProfileDoc.getItemValueInteger("Reconnect_n");

			timeDelay = sysProfileDoc.getItemValueInteger("TimeDelay_n");

			YReply = sysProfileDoc.getItemValueString("YReply_x");

			RReply = sysProfileDoc.getItemValueString("RReply_x");

			NReply = sysProfileDoc.getItemValueString("NCount_x");

			bondSend = sysProfileDoc.getItemValueString("BondSend_x");

			System.out.println(" <<< ----- Start - Price Declaring System KSDA ----- >>>");					     											     					

			System.out.println(" >>> Bond Price to be sent to KSDA : " + bondSend);

			System.out.println(" >>> Total no. of possible attempts for connecting to the server : " + reConnect);					     		

			if ( bondSend.equalsIgnoreCase("Yes") ) {					

				// check for Port and Host IPAddress

				if ( ip == null ) {

					errlog.logAction ( "*Error : IP Address is NULL "  + client.getErrorMsg() );

				}

				else {	

					if (port != 0) {

				          client = new Dealer (ip,port);

					}

					else {

				         client = new Dealer (ip);

					}

				errlog.logAction (" Total no. of possible attempts for connecting to the server : " + reConnect);	 

				// ********Start added by Jayesh on 15Aug06

				connectstatus = "SuccessFirst";

			

				if (client.connect(reConnect) == 0) {

					System.out.println(" >>> Connection not successfull primary ip");					     								

					errlog.logAction ("*No. of attempts made : " + client.reConnect);

					errlog.logError(0, client.getErrorMsg());

					connectstatus = "Failure";

					

					if ( altip == null) {

						errlog.logAction ( "*Error : Alternate IP Address is NULL "  + client.getErrorMsg() );							

					}

					else {

						if (port != 0) {

							client = new Dealer (altip,port);								

						}

						else {

							client = new Dealer (ip);

						}

						

						if (client.connect(reConnect) == 0) {

							System.out.println(" >>> Connection not successfull to alternate ip");					     								

							errlog.logAction ("*No. of attempts made : " + client.reConnect);

							errlog.logError(0, client.getErrorMsg());

							connectstatus = "Failure";

						}

						else {

							connectstatus = "SuccessSecond";

							System.out.println(" >>> Connection successfull to alternate ip");

						}

							

					}

				}

				if ( connectstatus == "Failure"){

					System.out.println(" >>> Connection not successfull to either of ip addresses");	

					//do nothing logging is already done

				}					

				//if (client.connect(reConnect) == 0) {										

				//	System.out.println(" >>> Connection not successfull");					     								

				//	errlog.logAction ("*No. of attempts made : " + client.reConnect);

				//	errlog.logError(0, client.getErrorMsg());	

				//}

  				// ********End added by Jayesh on 15Aug06

				else { // initiating client connection...				     				

					System.out.println(" >>> Connection is successfull");					     											     	

					errlog.logAction (" No. of attempts made before connecting to the server : " + client.reConnect);

					

					if (connectstatus=="SuccessFirst"){

						errlog.logAction(" Client Connection Passed to the server " + ip + " on port " + port );

		    				System.out.println(" >>> Client Connection Passed to the server " + ip + " on port " + port );

					}

					else {

						errlog.logAction(" Client Connection Passed to the server " + altip + " on port " + port );

	    					System.out.println(" >>> Client Connection Passed to the server " + altip + " on port " + port );

					}

// date = doc.getItemValueString (“ComposedOn”);

					dealercode = doc.getItemValueString ("DealerCode_x");						

					String date =  Date_Time.toString();						

					String month = date.substring(0,2);

					String day = date.substring(3,5);

					String year = date.substring(6,10);						

					String format = year + month + day;						

			     	key = format + dealercode; 

		     	 	theInput = key + sign [ 0 ];    

			      	theOutput = filler ( theInput ); // check for leading empty spaces

		     	 	client.printOutput ( theOutput ); // send ouput to server

		     	 	errlog.logAction (" Client Says   'S' : " + theOutput);

					System.out.println(" >>> Client Says   'S' : " + theOutput);					     								

					System.out.println(" >>> wait for server resp for signStatus 'Y' : " + YReply);

		               try { 

						TimeCheck();

		 				serverInput = client.processInput('S', key, YReply, 0); 

		 			}

					catch ( Exception ioe ) {					

						   errlog.logError ( 0, client.getErrorMsg() );

			  	             System.out.println(" >>> Exception : " + ioe);							   

					}		

					if ( serverInput == null ) {

						errlog.logAction("*Status 'Y' not reached or ServerInput is NULL. Failed to get Response from Server" );

					}

					else {			

					     if ( !YReply.equalsIgnoreCase("N") ) {	

					     	errlog.logAction(" Server Resp 'Y' : " + serverInput);

					     	System.out.println(" >>> Server Resp 'Y' : " + serverInput);

					     }

						try {

							status = serverInput.charAt ( 11 );		

					          Serverkey = serverInput.substring ( 0, 11 );					          

						} catch (Exception e) { 

							System.out.println(" >>> Exception in getting status : " + e); 

							errlog.logAction("* Exception in getting status : " + e.getMessage());

						}

						if (status == 'Y') {

							DocSendCount = 0;

			      			doc = pendingView.getFirstDocument();	

						     while (doc != null) { 				



								DocSendCount += 1;

								//System.out.println("DocSendCount at start of loop: " + DocSendCount) ;									

// date = doc.getItemValueString (“ComposedOn”);

							     dealercode = doc.getItemValueString ("DealerCode_x");

								sequential = doc.getItemValueString ("Sequential_x");

								tranref  = doc.getItemValueString ("TranRef_x");

								typecode = doc.getItemValueString ("TypeCode_x");

								standardcode = doc.getItemValueString ("StandardCode_x");

								

								//Bond Type code is being retrieved from the document here...use the array instead...

// bondtypecode = doc.getItemValueString (“BondTypeCode_x”);

								//bondtypecode = hp.CodeTable[1][count];

								bondtypecode = hp.CodeTable[1][DocSendCount-1];



								//Bond name is being retrieved from the document here...use the array instead...

// bondname = doc.getItemValueString (“BondName_x”);

								//bondname = hp.CodeTable[0][count];

								//bondname = hp.CodeTable[0][DocSendCount-1] ;

								bondname = hp.CodeTable[0][DocSendCount-1] + "                              " ;

								bondname = bondname.substring(0, 30) ;

								System.out.println(" >>> Bond Name (Korean) : " + bondname);

								inputtime = doc.getItemValueString ("InputTime_x");

								askyieldrate = doc.getItemValueString ("AskYieldRate_n");

								bidyieldrate = doc.getItemValueString ("BidYieldRate_n");

								sellingprice = doc.getItemValueString ("SellingPrice_x");

								buyingprice = doc.getItemValueString ("BuyingPrice_x");

								sellingvolume = doc.getItemValueString ("SellingVolume_x");

								buyingvolume = doc.getItemValueString ("BuyingVolume_x");

								issuedate = doc.getItemValueString ("IssueDate_x");

								couponrate = doc.getItemValueString ("CouponRate_n");

								maturity = doc.getItemValueString ("Maturity_x");

								discountrate = doc.getItemValueString ("DiscountRate_n");

								retentionperiod = doc.getItemValueString ("RetentionPeriod_x");

								rateofreturnaftertax = doc.getItemValueString ("RateOfReturn_n");

								interestpaymentcondition = doc.getItemValueString ("InterestPayment_x");

								classification = doc.getItemValueString ("Classification_x");

		     					key = format + dealercode;     			     			     					

					 		 	referdatalist = sequential + tranref + typecode + standardcode + bondtypecode + 

					 	                            		bondname + inputtime + askyieldrate + bidyieldrate + sellingprice +  

					 								buyingprice + sellingvolume + buyingvolume + issuedate + 

					 								couponrate + maturity + discountrate + retentionperiod  +

					 								rateofreturnaftertax + interestpaymentcondition + classification;

								theOutput =  key + sign[2] + referdatalist;

								client.printOutput ( theOutput );	// Send data to server

								errlog.logAction(" Client Says   'R' : " + theOutput);

								System.out.println(" >>> Client Says 'R' : " + theOutput);	

								System.out.println(" >>> wait for server resp for signStatus 'R' with data & OK/NO : " + RReply);	

					               try {

									TimeCheck(); // Delay few secs before reading server's response

		 							serverInput = client.processInput('R', key, RReply, 0); // reading server's response

					 			}

								catch ( Exception ioe ) {

									   errlog.logError ( 0, client.getErrorMsg() );

							             System.out.println(" >>> Exception : " + ioe);										   

								}									

								if ( serverInput == null ) {

									errlog.logAction("*Status 'R' not reached or ServerInput is NULL. Failed to get Response from Server" );								

								}	

								else {

								     if ( !RReply.equalsIgnoreCase("N") ) {											

									     errlog.logAction (" Server Resp 'R' : " + serverInput);

									     System.out.println(" >>> Server Resp 'R' : " + serverInput);

									}

									try {

										status = serverInput.charAt ( 11 );		

									} catch (Exception e) { 

										System.out.println(" >>> Exception in getting status : " + e); 

									}										

					                     if (status == 'R') {	     

								      	char UpdateReturn1stChar = serverInput.charAt ( 12 );

				       					char UpdateReturn2ndChar  =  serverInput.charAt ( 13 );

										System.out.println(" >>> OK/NO Status ! : " + UpdateReturn1stChar + UpdateReturn2ndChar);					       															

			    	       					//Status update here

						      			if ( ( UpdateReturn1stChar == 'O' && UpdateReturn2ndChar == 'K' ) || 

											( UpdateReturn1stChar == 'o' && UpdateReturn2ndChar == 'k' ) ) {

								  	     	doc.replaceItemValue("Status_x","Submitted to KSDA");

								  			ClientDocCount += 1;	

								  			System.out.println (" >>> Document count [OK] : " + ClientDocCount);										

											errlog.logAction(" Successfuly submitted to KSDA, 'OK' :" + serverInput);		

				      					}		      			

					      				else {

						      				 doc.replaceItemValue("Status_x","Failed update to KSDA");				      										  	     							      				

								  	     	 System.out.println (" >>> Document count [NO] : " + ClientDocCount);																				

											 errlog.logAction("*Failed submitted to KSDA, 'NO' :" + serverInput);																	  	     						      				

						      			}

						      			doc.save(false,false);

					  				}  // END check status = 'R'	



/* --------------------------------------

									else

									{

										errlog.logAction("* Server not sending 'R' flag to Client or Incorrect Key pair.");										

									}			    					

----------------------------------- */									



								}	// END check serverInput != null	

								pendingView.refresh() ; //refreshing the view to remove the previous doc

								//doc = pendingView.getNextDocument(doc);  // iterate next doc						

								doc = pendingView.getFirstDocument() ;  // iterate next doc						

							}  // ENDof while doc!=null

							

							if (DocSendCount <= 0) {

								errlog.logAction("*Zero or No Documents found");

								client.disconnect(); // disconnect client

							}

							else {							

								theInput = key + sign[3];

								theOutput = filler ( theInput );

								client.printOutput (theOutput );	// Send data to server with 'E'																										

								errlog.logAction(" Client Says   'E' : " + theOutput);		

								System.out.println(" >>> Client Says 'E' : " + theOutput);						

								System.out.println(" >>> wait for server resp for signStatus 'N' counts : " + NReply);	

					               try { 			

									TimeCheck();								

			 						serverInput = client.processInput('E', key, NReply, DocSendCount);

					 			}

								catch ( Exception ioe ) {

									   errlog.logError ( 0, client.getErrorMsg() );

								        System.out.println(" >>> Exception : " + ioe);										   

								}		

								if ( serverInput == null ) {

									errlog.logAction("*Status 'N' not reached or ServerInput is NULL. Failed to get Response from Server" );																	

								}

								else {									

								  if ( !NReply.equalsIgnoreCase("N") ) {											

								     errlog.logAction(" Server Resp 'N' : " + serverInput);

								     System.out.println(" >>> Server Resp 'N' : " + serverInput);

								  }

								  try {

								 	 status = serverInput.charAt ( 11 );		

								  } catch (Exception e) { 

									   System.out.println(" >>> Exception in getting status : " + e); 

								  }								  

								  if ( status == 'N' ) {

									client.disconnect(); // disconnect client

								  }



/* -----------------------------------

								  else

								  {

									errlog.logAction("* Server not sending N flag to Client.");								  	

								  }	

--------------------------------- */								  



								} // END check status == 'N'

							}	// END check else DocSendCount				

					} //End of key and Y check				



/* -----------------------------						

						else

						{

							errlog.logAction("* Server not sending Y flag to Client or Incorrect Key pair.");

						}						

------------------------------ */						



					}  // End of else serverInput != null 



					errlog.logAction(" Total no. of docments sent to the server : " + DocSendCount);

					errlog.logAction(" No. of documents successfully updated  : " + ClientDocCount);

					System.out.println("~~~~  Total no. of docments sent to the server : " + DocSendCount);

					System.out.println("*****  No. of documents successfully updated  : " + ClientDocCount);

			} //Connection Check End

			errlog.logAction(" Connection terminated");

			System.out.println(" >>> Connection terminated");

			System.out.println(" <<<----- End - Price Declaring System KSDA ----->>>");					     											     									

		   } // END IPAddress null check	

		 }

		 else {

		 	errlog.logAction("*Bond Details is diabled.");

		 }   

	} // Doc null check

} // End of Main try

catch ( NotesException ne ) {

   try {	

      if (ne.id == NotesError.NOTES_ERR_NOTAFILE) {

		   errlog.logError ( ne.id, "*Database open failed" );     			   

 	 }		   

      else {

		   errlog.logError ( ne.id, ne.text );     			        			   

	 } 

   }

   catch ( Exception  e ) {

   	// Exception

   }		 

 }	 

} // END main

// Time Delay for few secs before reading server’s response

public void TimeCheck() {

try {

  stDateTime = session.createDateTime("Today");

  crDateTime = session.createDateTime("Today");

  long AgentRunSec = 0;

  long tmploopvar =0;

  stDateTime.setNow(); 

  do {

  	tmploopvar = tmploopvar + 1;

  	crDateTime.setNow(); 

      AgentRunSec = crDateTime.timeDifference(stDateTime);		          

	if ((tmploopvar % 2000) == 0 ) {

		//System.out.println (" >>> Start Time " + stDateTime + " <<<>>> Cur Time :" + crDateTime);

 	 	//System.out.println (" >>> Agent running for " + AgentRunSec + " secs. of loop " + tmploopvar) ;

  	}

	} while (AgentRunSec <= timeDelay ); // (tmploopvar < 20000 ); 

} catch (Exception e ) { 

	// Exception

}	

}

// check for fillers ( empty spaces )

  public String filler ( String output ) {     	

  	StringBuffer data = new StringBuffer ( MAXBYTE );

     data.append ( output );

  	int len = output.length();     		

  	try {     		

  	    	  if ( len < MAXBYTE ) {

		     	int length =  ( MAXBYTE - len );			     	

  			     for ( int i= 0; i < length; i++ ) { 

					data.append ( "*" ); 

	 			}			

		  }

		  else {

		  	System.out.println(" >>> Data Length is not 152 : " + len);

		  }		    

	  }			 

	  catch ( Exception e ) {

	  	try {

			   errlog.logError ( 0, e.getMessage() );     			        			   

		 }

		 catch ( Exception in ) {

			try {			 	

				errlog.logAction("*Exception in filler : " + in.getMessage() );

			} catch ( Exception in2 ) {

			}	

		 } 	

	   }	

 return data.toString();														 

 }     

} // END Main class