<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Recent changes to Home</title><link>https://sourceforge.net/p/tthreads/home/Home/</link><description>Recent changes to Home</description><atom:link href="https://sourceforge.net/p/tthreads/home/Home/feed" rel="self"/><language>en</language><lastBuildDate>Mon, 31 Oct 2011 02:23:09 -0000</lastBuildDate><atom:link href="https://sourceforge.net/p/tthreads/home/Home/feed" rel="self" type="application/rss+xml"/><item><title>WikiPage Home modified by Mohammed Ejaz</title><link>https://sourceforge.net/p/tthreads/home/Home/</link><description>&lt;pre&gt;--- v20 
+++ v21 
@@ -3,7 +3,7 @@
 
 This library extends java.lang.Thread class to provide clean and reliable thread terminating capability. 
 
-The usual method prescribed by many, to simulate thread kill, is to use a control variable which thread needs to keep checking. When thread needs to be killed, it is sent an interrupt signal and the interrupt handler sets this variable to some value to indicate that thread needs to die. This can be difficult to implement - particularly in deeply nested methods. It also works only when thread is blocked/busy in database call or waiting for socket or reading a file. 
+The usual method prescribed by many, to simulate thread kill, is to use a control variable which thread needs to keep checking. When thread needs to be killed, it is sent an interrupt signal and the interrupt handler sets this variable to some value to indicate that thread needs to die. This can be difficult to implement - particularly in deeply nested methods. It also works only when thread is **NOT** blocked/busy in database call or waiting for socket or reading a file. 
 
 *Note that the default interrupt function available on Thread works only when the thread is in sleep/wait state.*
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mohammed Ejaz</dc:creator><pubDate>Mon, 31 Oct 2011 02:23:09 -0000</pubDate><guid>https://sourceforge.net1cf1455b8d1d8a73055d533ba163a6f55d9504a6</guid></item><item><title>WikiPage Home modified by Mohammed Ejaz</title><link>https://sourceforge.net/p/tthreads/home/Home/</link><description>&lt;pre&gt;--- v19 
+++ v20 
@@ -74,7 +74,7 @@
             */
             
             // Test Case : Thread is busy reading from file (note there is no sleep!)
-            final BufferedReader rdr = new BufferedReader(new FileReader("c:/docs/Test.txt"));
+            final RandomAccessFile rdr = new RandomAccessFile("c:/docs/Test.txt");
             // Add hook to close the open file handle
             TerminativeThread.push(new ThreadTerminateHook() {
                 public void terminate() {
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mohammed Ejaz</dc:creator><pubDate>Sun, 30 Oct 2011 19:39:20 -0000</pubDate><guid>https://sourceforge.netfb0060a619628ef4685d7bf54886ede2c858188e</guid></item><item><title>WikiPage Home modified by Mohammed Ejaz</title><link>https://sourceforge.net/p/tthreads/home/Home/</link><description>&lt;pre&gt;--- v18 
+++ v19 
@@ -40,41 +40,42 @@
 
 Worker.java
 ===========
-
+    // Add hook to set control variable
     logger.info("Inside run() --");
     TerminativeThread.push(new ThreadTerminateHook() {
         public void terminate() {
             logger.info("Set abort = true --");
             abort = true;
         }
     });
     
     try {
         while (!abort) { // abort is class member variable
             // Test Case : Thread is waiting for a socket
             /*
             try {
                 final ServerSocket ssock = new ServerSocket(port);
-                
+                // Add hook to close this server socket
                 TerminativeThread.push(new ThreadTerminateHook() {
                     public void terminate() {
                         logger.info("Inside ThreadShutDownHook -- ");
                         try {
                             ssock.close();
                         } catch (Exception e) {
                         }
                         logger.info("Leaving ThreadShutDownHook -- ");
                     }
                 });
                 
                 ssock.accept();
             } catch (Exception e) {
                 e.printStackTrace();
             }
             */
             
             // Test Case : Thread is busy reading from file (note there is no sleep!)
             final BufferedReader rdr = new BufferedReader(new FileReader("c:/docs/Test.txt"));
+            // Add hook to close the open file handle
             TerminativeThread.push(new ThreadTerminateHook() {
                 public void terminate() {
                     logger.info("Close rdr --");
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mohammed Ejaz</dc:creator><pubDate>Sun, 30 Oct 2011 19:33:19 -0000</pubDate><guid>https://sourceforge.netd546b3c56d9e1ebc722aa9f8658ccf08d31fdfbf</guid></item><item><title>WikiPage Home modified by Mohammed Ejaz</title><link>https://sourceforge.net/p/tthreads/home/Home/</link><description>&lt;pre&gt;--- v17 
+++ v18 
@@ -3,7 +3,7 @@
 
 This library extends java.lang.Thread class to provide clean and reliable thread terminating capability. 
 
-The usual method prescribed by many, to simulate thread kill, is to use a control variable which thread needs to keep checking. When thread needs to be killed, it is sent an interrupt signal and the interrupt handler sets this variable to some value to indicate that thread needs to die. This can be difficult to implement - particularly in deeply nested methods. It also works only when thread can come out of a blocking operation like database call or accepting a socket or finishing reading a file. 
+The usual method prescribed by many, to simulate thread kill, is to use a control variable which thread needs to keep checking. When thread needs to be killed, it is sent an interrupt signal and the interrupt handler sets this variable to some value to indicate that thread needs to die. This can be difficult to implement - particularly in deeply nested methods. It also works only when thread is blocked/busy in database call or waiting for socket or reading a file. 
 
 *Note that the default interrupt function available on Thread works only when the thread is in sleep/wait state.*
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mohammed Ejaz</dc:creator><pubDate>Sun, 30 Oct 2011 19:32:11 -0000</pubDate><guid>https://sourceforge.net1cbe7df5106fe399159be4bc4cdbf803ccde951f</guid></item><item><title>WikiPage Home modified by Mohammed Ejaz</title><link>https://sourceforge.net/p/tthreads/home/Home/</link><description>&lt;pre&gt;--- v16 
+++ v17 
@@ -3,7 +3,7 @@
 
 This library extends java.lang.Thread class to provide clean and reliable thread terminating capability. 
 
-The usual method prescribed by many, to simulate thread kill, is to use a control variable which thread needs to keep checking. When thread needs to be killed, it is sent an interrupt signal and the interrupt handler sets this variable to some value to indicate that thread needs to die. This works only when thread can come out of a blocking operation like database call or accepting a socket or finishing reading a file. 
+The usual method prescribed by many, to simulate thread kill, is to use a control variable which thread needs to keep checking. When thread needs to be killed, it is sent an interrupt signal and the interrupt handler sets this variable to some value to indicate that thread needs to die. This can be difficult to implement - particularly in deeply nested methods. It also works only when thread can come out of a blocking operation like database call or accepting a socket or finishing reading a file. 
 
 *Note that the default interrupt function available on Thread works only when the thread is in sleep/wait state.*
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mohammed Ejaz</dc:creator><pubDate>Sun, 30 Oct 2011 19:31:11 -0000</pubDate><guid>https://sourceforge.net0fa6267c3354aa5bd7225992da5b70af9ac635ad</guid></item><item><title>WikiPage Home modified by Mohammed Ejaz</title><link>https://sourceforge.net/p/tthreads/home/Home/</link><description>&lt;pre&gt;--- v15 
+++ v16 
@@ -1,5 +1,5 @@
-[[project_admins]]
-[[download_button]]
+Overview
+========
 
 This library extends java.lang.Thread class to provide clean and reliable thread terminating capability. 
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mohammed Ejaz</dc:creator><pubDate>Sun, 30 Oct 2011 19:29:47 -0000</pubDate><guid>https://sourceforge.neta6319e9f43016ba1d98a9916d84ce4109e453dcd</guid></item><item><title>WikiPage Home modified by Mohammed Ejaz</title><link>https://sourceforge.net/p/tthreads/home/Home/</link><description>&lt;pre&gt;--- v14 
+++ v15 
@@ -14,3 +14,138 @@
 TerminateThread class extends Thread class. It keeps a stack of terminate hooks (per instance of TerminateThread) which are added by a programmer at run time. Thus when developer invokes interrupt on TerminativeThread's instance, it checks all the available hooks and invokes each one them in the order in which they were added
 
 
+Here's how you use it ...
+
+Test.java
+=========
+    Thread t1 = new TerminativeThread(new Worker(5080));
+    // Thread t1 = new Thread(new WorkerThread(5080));
+    t1.start();
+
+    Thread t2 = new TerminativeThread(new Worker(5081));
+    // Thread t2 = new Thread(new WorkerThread(5081));
+    t2.start();
+    
+    logger.info("Sleep --");
+    Thread.sleep(1000 * 5);
+    
+    logger.info("Calling kill --");
+    t1.interrupt();
+
+    logger.info("Sleep --");
+    Thread.sleep(1000 * 5);
+    
+    logger.info("Calling kill --");
+    t2.interrupt();
+
+Worker.java
+===========
+
+    logger.info("Inside run() --");
+    TerminativeThread.push(new ThreadTerminateHook() {
+        public void terminate() {
+            logger.info("Set abort = true --");
+            abort = true;
+        }
+    });
+    
+    try {
+        while (!abort) { // abort is class member variable
+            // Test Case : Thread is waiting for a socket
+            /*
+            try {
+                final ServerSocket ssock = new ServerSocket(port);
+                
+                TerminativeThread.push(new ThreadTerminateHook() {
+                    public void terminate() {
+                        logger.info("Inside ThreadShutDownHook -- ");
+                        try {
+                            ssock.close();
+                        } catch (Exception e) {
+                        }
+                        logger.info("Leaving ThreadShutDownHook -- ");
+                    }
+                });
+                
+                ssock.accept();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+            */
+            
+            // Test Case : Thread is busy reading from file (note there is no sleep!)
+            final BufferedReader rdr = new BufferedReader(new FileReader("c:/docs/Test.txt"));
+            TerminativeThread.push(new ThreadTerminateHook() {
+                public void terminate() {
+                    logger.info("Close rdr --");
+                    try {
+                        rdr.close();
+                    } catch (Exception e) {
+                    }
+                }
+            });
+            try {
+                String line = null;					
+                while ((line=rdr.readLine()) != null) {
+                    ;
+                }
+            } catch (Exception e) {
+                e.printStackTrace();
+            } finally {
+                Thread.yield();
+                try { rdr.close(); } catch (Exception e) {}
+                TerminativeThread.pop();
+            }
+        }
+    } catch (Throwable e) {
+        e.printStackTrace();
+    } finally {
+        TerminativeThread.clear();
+    }
+    
+    logger.info("Leaving run() --");
+
+
+Output
+======
+
+Oct 30, 2011 1:28:18 PM Test test
+INFO: Starting Threads --
+Oct 30, 2011 1:28:18 PM Test test
+INFO: Sleep --
+Oct 30, 2011 1:28:18 PM Worker run
+INFO: Inside run() --
+Oct 30, 2011 1:28:18 PM Worker run
+INFO: Inside run() --
+Oct 30, 2011 1:28:28 PM Test test
+INFO: Calling kill --
+Oct 30, 2011 1:28:28 PM open.ejaz.tthread.TerminativeThread interrupt
+WARNING: TID 10 Inside interrrupt --
+Oct 30, 2011 1:28:28 PM Worker$2 terminate
+INFO: Close rdr --
+java.io.IOException: Read error
+	at java.io.RandomAccessFile.read(Native Method)
+	at java.io.RandomAccessFile.readLine(RandomAccessFile.java:871)
+	at Worker.run(Worker.java:67)
+	at java.lang.Thread.run(Thread.java:662)
+Oct 30, 2011 1:28:28 PM Worker$1 terminate
+INFO: Set abort = true --
+Oct 30, 2011 1:28:28 PM Test test
+INFO: Sleep --
+Oct 30, 2011 1:28:28 PM Worker run
+INFO: Leaving run() --
+Oct 30, 2011 1:28:35 PM Test test
+INFO: Calling kill --
+Oct 30, 2011 1:28:35 PM open.ejaz.tthread.TerminativeThread interrupt
+WARNING: TID 11 Inside interrrupt --
+Oct 30, 2011 1:28:35 PM Worker$2 terminate
+INFO: Close rdr --
+java.io.IOException: Read error
+	at java.io.RandomAccessFile.read(Native Method)
+	at java.io.RandomAccessFile.readLine(RandomAccessFile.java:871)
+	at Worker.run(Worker.java:67)
+	at java.lang.Thread.run(Thread.java:662)
+Oct 30, 2011 1:28:35 PM Worker$1 terminate
+INFO: Set abort = true --
+Oct 30, 2011 1:28:35 PM Worker run
+INFO: Leaving run() --
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mohammed Ejaz</dc:creator><pubDate>Sun, 30 Oct 2011 19:27:00 -0000</pubDate><guid>https://sourceforge.net68f0ac4295962d21c7c2c2fd51def95f68334d3b</guid></item><item><title>WikiPage Home modified by Mohammed Ejaz</title><link>https://sourceforge.net/p/tthreads/home/Home/</link><description>&lt;pre&gt;--- v13 
+++ v14 
@@ -9,7 +9,7 @@
 
 **There is no way to interrupt a busy thread**
 
-The new approach uses **control resource** and **thread shutdown hook**. The control resource could be an open file or database connection or anything else which is crucial to thread's normal life cycle. If you close this resource, thread dies. The programmer adds the hooks to close these control resources. 
+The new approach uses **control resource** and **thread shutdown hook**. The control resource could be an open file or database connection or anything else which is crucial to thread's normal life cycle. If you close this resource, thread dies. The programmer adds (or removes) the hooks to close these control resources. 
 
 TerminateThread class extends Thread class. It keeps a stack of terminate hooks (per instance of TerminateThread) which are added by a programmer at run time. Thus when developer invokes interrupt on TerminativeThread's instance, it checks all the available hooks and invokes each one them in the order in which they were added
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mohammed Ejaz</dc:creator><pubDate>Sun, 30 Oct 2011 19:24:41 -0000</pubDate><guid>https://sourceforge.netdfd7784aa67f13981c7b87b86d70e701db2e1071</guid></item><item><title>WikiPage Home modified by Mohammed Ejaz</title><link>https://sourceforge.net/p/tthreads/home/Home/</link><description>&lt;pre&gt;--- v12 
+++ v13 
@@ -9,7 +9,7 @@
 
 **There is no way to interrupt a busy thread**
 
-The new approach uses **control resource** and **thread shutdown hook** concepts. The control resource could be an open file or database connection or anything else which is crucial to thread's normal life cycle. If you close this resource, thread dies. The programmer adds the hooks to close these control resources. 
+The new approach uses **control resource** and **thread shutdown hook**. The control resource could be an open file or database connection or anything else which is crucial to thread's normal life cycle. If you close this resource, thread dies. The programmer adds the hooks to close these control resources. 
 
 TerminateThread class extends Thread class. It keeps a stack of terminate hooks (per instance of TerminateThread) which are added by a programmer at run time. Thus when developer invokes interrupt on TerminativeThread's instance, it checks all the available hooks and invokes each one them in the order in which they were added
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mohammed Ejaz</dc:creator><pubDate>Sun, 30 Oct 2011 19:24:13 -0000</pubDate><guid>https://sourceforge.netfc982f4e6e1ba1b83cb9bbd0ec388797ae361401</guid></item><item><title>WikiPage Home modified by Mohammed Ejaz</title><link>https://sourceforge.net/p/tthreads/home/Home/</link><description>&lt;pre&gt;--- v11 
+++ v12 
@@ -9,20 +9,7 @@
 
 **There is no way to interrupt a busy thread**
 
-The new approach uses **control resource** and **thread shutdown hook** concepts. The control resource could be an open file or database connection or anything else which is crucial to thread's normal life cycle. If you close this resource, thread dies. The programmer adds the hooks to close these control resources. Here's what a hook looks like ...
-
-&lt;a href="#"&gt;
-package open.ejaz.tthread;
-/**
- * Simple thread terminate hook interface 
- * 
- * @author ejaz
- *
- */
-public interface ThreadTerminateHook {
-    public void terminate();
-}
-&lt;/a&gt;
+The new approach uses **control resource** and **thread shutdown hook** concepts. The control resource could be an open file or database connection or anything else which is crucial to thread's normal life cycle. If you close this resource, thread dies. The programmer adds the hooks to close these control resources. 
 
 TerminateThread class extends Thread class. It keeps a stack of terminate hooks (per instance of TerminateThread) which are added by a programmer at run time. Thus when developer invokes interrupt on TerminativeThread's instance, it checks all the available hooks and invokes each one them in the order in which they were added
 
&lt;/pre&gt;</description><dc:creator xmlns:dc="http://purl.org/dc/elements/1.1/">Mohammed Ejaz</dc:creator><pubDate>Sun, 30 Oct 2011 15:14:54 -0000</pubDate><guid>https://sourceforge.net8accbd3ab70e6e1a71496d78f3858735b6751621</guid></item></channel></rss>