package testsuite.simple;

import testsuite.BaseTestCase;
import java.lang.Runnable;
import java.sql.SQLException;


public class TestBug24721 extends BaseTestCase {

	class CloseThread implements Runnable{
		   Thread t;
		   CloseThread () {
		      t = new Thread(this,"Close thread");
		      t.start();
		   }
		   public void run() {
		      System.out.println("*Close* thread started");
		      try {
		    	  Thread.sleep(1500);
		      } catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
		      }
		      try {
		    	    System.out.println("*Close* thread, about to do stmt.execute");  
		    	  	stmt.execute("USE test");
		    	    System.out.println("*Close* thread, stmt.execute done");  
					
		    	    System.out.println("*Close* thread, about to do stmt.close");  
		    	    //stmt.close();
		    	    System.out.println("*Close* thread, stmt.close done");  
		    	    
		    	    for(int i=0;i<10000;i++) {
		    	    	System.out.print(i);//Close thr w 
		    	    }
		    	    
			   } catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
			   }
			   System.out.println(""); 
		      System.out.println("*Close* thread terminated");
			   System.out.println(""); 
		   }
		}

	class CancelThread implements Runnable{
		   Thread t;
		   CancelThread () {
		      t = new Thread(this,"Cancel thread");
		      t.start();
		   }
		   public void run() {
		      System.out.println("*Cancel* thread started");
		      try {
				Thread.sleep(1500);
			} catch (InterruptedException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}		      
		      try {
		    	  System.out.println("*Cancel* thread, about to do stmt.cancel()");
				   System.out.println(""); 
		    	    for(int i=0;i<10000;i++) {
		    	    	System.out.print("2");//Cancel thr w 
		    	    }
		    	  stmt.cancel();
				   System.out.println(""); 
		    	  System.out.println("*Cancel* thread, stmt.cancel() done");  
		      } catch (SQLException e) {
				// TODO Auto-generated catch block
		    	  e.printStackTrace();
		      }
			   System.out.println("");
			   System.out.println("*Cancel* thread terminated");
		   }
		}

	public TestBug24721(String name) {
		// TODO Auto-generated constructor stub
		super(name);
	}

	public void testBug24065() throws Exception {
		
		CloseThread thr1 = new CloseThread();
		CancelThread thr2 = new CancelThread();
		
		 try {
	         System.out.println("Threads Joining.");
	         thr1.t.join();
	         thr2.t.join();
	      } catch (InterruptedException e) {
	        System.out.println(
	                  "Exception: Thread main interrupted.");
	      }		
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		junit.textui.TestRunner.run(TestBug24721.class);
	}

}
