KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > schlichtherle > io > LegacyExecutor


1 /*
2  * LegacyExecutor.java
3  *
4  * Created on 18. Dezember 2006, 01:52
5  */

6 /*
7  * Copyright 2006 Schlichtherle IT Services
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package de.schlichtherle.io;
23
24 /**
25  * @author Christian Schlichtherle
26  * @version @version@
27  * @since TrueZIP 6.4
28  */

29 final class LegacyExecutor implements File.Executor {
30     private final String JavaDoc threadName;
31
32     /**
33      * Constructs a new <code>LegacyExecutor</code>.
34      * This constructor is public in order to enable reflective access
35      * (currently unused)!
36      */

37     public LegacyExecutor(String JavaDoc threadName) {
38         assert threadName != null;
39         this.threadName = threadName;
40     }
41
42     public File.Task submit(Runnable JavaDoc target) {
43         assert target != null;
44         return new LegacyTask(target, threadName);
45     }
46
47     private static final class LegacyTask implements File.Task {
48         private final Thread JavaDoc thread;
49
50         private LegacyTask(Runnable JavaDoc target, String JavaDoc threadName) {
51             assert target != null;
52             assert threadName != null;
53             thread = new Thread JavaDoc(target, threadName);
54             thread.start();
55         }
56
57         public void cancel() {
58             thread.interrupt();
59             while (true) {
60                 try {
61                     thread.join();
62                     break;
63                 } catch (InterruptedException JavaDoc ignored) {
64                 }
65             }
66         }
67     }
68 }
69
Popular Tags