KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > tests > DistributedHashDeadLock


1 package org.jgroups.tests;
2
3
4 import org.jgroups.ChannelException;
5 import org.jgroups.blocks.DistributedHashtable;
6 import org.jgroups.util.Util;
7
8
9
10
11 /**
12  * Title: Java Groups Communications
13  * Description: Contact me at <a HREF="mailto:filip@filip.net">filip@filip.net</a>
14  * Copyright: Copyright (c) 2002
15  * Company: www.filip.net
16  * @author Filip Hanik
17  * @version 1.0
18  */

19 public class DistributedHashDeadLock {
20
21     public DistributedHashDeadLock() {
22     }
23
24     public static void main(String JavaDoc arg[]) throws ChannelException {
25         System.out.println("Starting hashtable");
26         String JavaDoc props="UDP(mcast_addr=224.0.0.35;mcast_port=45566;ip_ttl=32;mcast_send_buf_size=150000;mcast_recv_buf_size=80000):" +
27                 "PING(timeout=2000;num_initial_members=3):" +
28                 "MERGE2:" +
29                 "FD:" +
30                 "VERIFY_SUSPECT(timeout=1500):" +
31                 "pbcast.NAKACK(max_xmit_size=16000;gc_lag=1500;retransmit_timeout=600,1200,2400,4800):" +
32                 "UNICAST(timeout=2000):" +
33                 "pbcast.STABLE(desired_avg_gossip=20000):" +
34                 "FRAG(frag_size=16000;down_thread=false;up_thread=false):" +
35                 "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=true):" +
36                 "pbcast.STATE_TRANSFER";
37
38
39         DistributedHashtable distHash=new DistributedHashtable("ADMINT", null, props, 20000);
40         boolean odd=false;
41         int numberofelements=1000;
42
43         Util.sleep(5000);
44         System.out.println("size: " + distHash.size());
45         if(distHash.size() > 0)//The first instance counts up when numbers are even
46
{ //The second when numbers are odd
47
odd=true;
48         }
49         boolean fillup=false;
50         if(!odd) System.out.println("Loading hashtable with " + numberofelements + " elements. Don't start the other instance");
51         for(int i=0; !odd && i < numberofelements; i++)//if the table isn't full we fill it
52
{
53             if(i % 50 == 0) System.out.print(i + " ");
54             distHash.put("number" + i, new Integer JavaDoc(0));
55             fillup=true;
56         }
57         if(fillup) System.out.println("\n\nHashtable filled, you can now start the other instance\n");
58         System.out.println("initilising with odd: " + odd + " and size " + distHash.size());
59         while(true) {
60             try {
61                 System.out.println("#######################################################");
62                 Thread.sleep(10000);
63                 int count=0;
64                 for(int i=0; i < numberofelements; i++) {
65                     int value=((Integer JavaDoc)distHash.get("number" + i)).intValue();
66                     System.out.print(value + " ");
67                     if(i % 50 == 0) System.out.print("\n");
68                     if(odd && (value % 2 != 0))//If the number is odd, and the instance is supposed to count odd numbers up
69
{
70                         count++;
71                         value++;
72                         distHash.put("number" + i, new Integer JavaDoc(value));
73                         continue;
74                     }
75                     if(!odd && (value % 2 == 0))//If the number is even, and the instance is supposed to count even numbers up
76
{
77                         count++;
78                         value++;
79                         distHash.put("number" + i, new Integer JavaDoc(value));
80                         continue;
81                     }
82                 }
83                 System.out.println("\n" + odd + " through all session, changed: " + count);
84
85             }
86             catch(Exception JavaDoc e) {
87                 e.printStackTrace();
88             }
89         }
90
91     }
92 }
93
Popular Tags