1 /*
2  * Created on 28-Jun-2004
3  * Created by Paul Gardner
4  * Copyright (C) Azureus Software, Inc, All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
17  *
18  */
19 
20 package org.gudy.azureus2.core3.util;
21 
22 import java.util.WeakHashMap;
23 
24 
25 /**
26  * @author parg
27  * @deprecated - use AEThread2
28  */
29 
30 public abstract class
31 AEThread
32 	extends Thread
33 {
34 	private static WeakHashMap	our_thread_map = new WeakHashMap();
35 
36 	public
AEThread( String name )37 	AEThread(
38 		String	name )
39 	{
40 		super(name);
41 
42 		setDaemon( false );
43 	}
44 
45 	public
AEThread( String name, boolean daemon )46 	AEThread(
47 		String	name,
48 		boolean	daemon )
49 	{
50 		super(name);
51 
52 		setDaemon( daemon );
53 	}
54 
55 	public void
run()56 	run()
57 	{
58 		if ( AEThread2.TRACE_TIMES ){
59 
60 			System.out.println( TimeFormatter.milliStamp() + ": AEThread:start: " + this );
61 		}
62 
63 		try{
64 			/*
65 			if ( !isDaemon()){
66 
67 				System.out.println( "non-daemon thread:" + this );
68 			}
69 			*/
70 
71 			runSupport();
72 
73 		}catch( Throwable e ){
74 
75 			DebugLight.printStackTrace(e);
76 		}
77 
78 		// System.out.println( "Stop: " + this );
79 	}
80 
81 	public abstract void
runSupport()82 	runSupport();
83 
84 	public static boolean
isOurThread( Thread thread )85 	isOurThread(
86 		Thread	thread )
87 	{
88 		if ( thread instanceof AEThread ){
89 
90 			return( true );
91 		}
92 
93 		synchronized( our_thread_map ){
94 
95 			return( our_thread_map.get( thread ) != null );
96 		}
97 	}
98 
99 	public static void
setOurThread()100 	setOurThread()
101 	{
102 		setOurThread( Thread.currentThread());
103 	}
104 
105 	public static void
setOurThread( Thread thread )106 	setOurThread(
107 		Thread	thread )
108 	{
109 		if ( thread instanceof AEThread || thread instanceof AEThread2.threadWrapper ){
110 
111 			return;
112 		}
113 
114 		synchronized( our_thread_map ){
115 
116 			our_thread_map.put( thread, "" );
117 		}
118 	}
119 }
120