KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > oscache > base > GroupConcurrencyProblemTestCase


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 package com.opensymphony.oscache.base;
6
7 import com.opensymphony.oscache.general.GeneralCacheAdministrator;
8
9 import junit.framework.TestCase;
10
11 /**
12  * DOCUMENT ME!
13  *
14  * @author $author$
15  * @version $Revision: 1.1 $
16  */

17 public class GroupConcurrencyProblemTestCase extends TestCase {
18     private static GeneralCacheAdministrator cache = new GeneralCacheAdministrator();
19
20     public static void main(String JavaDoc[] args) {
21         System.out.println("START");
22
23         // Create some clients and start them running.
24
for (int i = 0; i < 100; i++) {
25             System.out.println("Creating thread: " + i);
26
27             new Client(i, cache).start();
28         }
29
30         System.out.println("END");
31     }
32 }
33
34
35 /* Inner class to hammer away at the cache. */
36 class Client extends Thread JavaDoc {
37     private static final int MAX_ITERATIONS = 1000;
38     private GeneralCacheAdministrator cache;
39     private int id;
40
41     public Client(int newId, GeneralCacheAdministrator newCache) {
42         super();
43         id = newId;
44         cache = newCache;
45     }
46
47     public void run() {
48         for (int i = 0; i < MAX_ITERATIONS; i++) {
49             /* Put an entry from this Client into the shared group.
50              */

51             cache.putInCache(Integer.toString(id), "Some interesting data", new String JavaDoc[] {
52                     "GLOBAL_GROUP"
53                 });
54
55             // Flush that group.
56
cache.flushGroup("GLOBAL_GROUP");
57         }
58     }
59 }
60
Popular Tags