01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package org.apache.axis2.jaxws.sample.parallelasync.common;
21:
22: import org.apache.axis2.jaxws.TestLogger;
23:
24: import java.util.concurrent.Executor;
25: import java.util.concurrent.ExecutorService;
26:
27: import javax.xml.ws.Service;
28:
29: public class KillerThread extends Thread {
30:
31: private Service svc = null;
32:
33: private boolean isKilled = false;
34: private boolean interrupt = false;
35:
36: private int waitUntilKillingSec = 30;
37:
38: public KillerThread(Service service, int client_max_sleep_sec) {
39: this .waitUntilKillingSec = client_max_sleep_sec;
40: this .svc = service;
41: }
42:
43: public void run() {
44: Executor e = svc.getExecutor();
45:
46: TestLogger.logger.debug("KillerThread: "
47: + e.getClass().getName());
48: ExecutorService es = (ExecutorService) e;
49:
50: int i = waitUntilKillingSec;
51: while (i > 0 && !interrupt) {
52:
53: try {
54: TestLogger.logger.debug("KillerThread: going to sleep");
55: Thread.sleep(1000);
56: i--;
57: } catch (InterruptedException e1) {
58: TestLogger.logger.debug("KillerThread: interrupted");
59: }
60: }
61:
62: // force executor to stop
63: if (!interrupt) {
64: isKilled = true;
65: es.shutdownNow();
66: }
67: }
68:
69: public boolean isKilled() {
70: return isKilled;
71: }
72:
73: public void abort() {
74: this .interrupt = true;
75: this.interrupt();
76: }
77: }
|