KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > concurrency > TestService


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

16
17 package test.concurrency;
18
19 /**
20  * An Axis service to test application scope. There should be exactly one
21  * instance of this class, if we end up with more then application scope
22  * isn't working correctly.
23  *
24  * @author Glen Daniels (gdaniels@apache.org)
25  */

26 public class TestService {
27     private static Object JavaDoc lock = new Object JavaDoc();
28
29     private static TestService singleton = null;
30     public static final String JavaDoc MESSAGE = "Hi there, come here often?";
31
32     public TestService() throws Exception JavaDoc {
33         synchronized (lock) {
34             if (singleton != null) {
35                 // We're not the first/only one, so throw an Exception!
36
throw new Exception JavaDoc("Multiple instances of TestService created!");
37             }
38
39             singleton = this;
40         }
41     }
42
43     public String JavaDoc hello() {
44         return MESSAGE;
45     }
46 }
47
Popular Tags