@@ -198,6 +198,7 @@ public static String getDataType(Object obj) {
198198 private int timeout = 30 * 1000 ;
199199 private int serial = 1 ;
200200 private Object serial_lock = new Object ();
201+ private ThreadQueue queue ;
201202
202203 /** Create DBus with specified EndPoint. */
203204 public DBus (EndPoint ep ) {
@@ -281,6 +282,11 @@ public static void setTCPTransportPort(int port) {
281282 public boolean connect () {
282283 String busname = ep .getEndPointName ();
283284 if (debug ) JFLog .log ("DBus:busName=" + busname );
285+ if (queue != null ) {
286+ queue .close ();
287+ queue = null ;
288+ }
289+ queue = new ThreadQueue ();
284290 return transport .connect (busname , this , new Runnable () {
285291 public void run () {
286292 reader = new Reader ();
@@ -298,6 +304,10 @@ public boolean disconnect() {
298304 reader .join ();
299305 }
300306 reader = null ;
307+ if (queue != null ) {
308+ queue .close ();
309+ queue = null ;
310+ }
301311 return result ;
302312 } catch (Exception e ) {
303313 JFLog .log (e );
@@ -1061,21 +1071,23 @@ private void method_call() throws Exception {
10611071 break ;
10621072 }
10631073 } else {
1064- //to avoid deadlock this must be done on a new thread : TODO : create a thread pool
1074+ //to avoid deadlock this must be done on a seperate thread
10651075 String _member = member ;
10661076 String _sender = sender ;
10671077 int _msg_serial = msg_serial ; //field value may change with next inbound msg
1068- new Thread () {
1069- public void run () {
1070- try {
1071- Object ret = ep .dispatch (_member , args );
1072- write_msg (MSG_RETURN , _sender , nextSerial (), _msg_serial , _member , new Object [] {ret });
1073- } catch (Exception e ) {
1074- if (debug ) JFLog .log (e );
1075- write_msg (MSG_ERROR , _sender , nextSerial (), _msg_serial , _member , new Object [] {e .toString ()});
1078+ queue .add (
1079+ new Runnable () {
1080+ public void run () {
1081+ try {
1082+ Object ret = ep .dispatch (_member , args );
1083+ write_msg (MSG_RETURN , _sender , nextSerial (), _msg_serial , _member , new Object [] {ret });
1084+ } catch (Exception e ) {
1085+ if (debug ) JFLog .log (e );
1086+ write_msg (MSG_ERROR , _sender , nextSerial (), _msg_serial , _member , new Object [] {e .toString ()});
1087+ }
10761088 }
10771089 }
1078- }. start ( );
1090+ );
10791091 }
10801092 } catch (Exception e ) {
10811093 if (debug ) JFLog .log (e );
0 commit comments