01: package org.jgroups.tests;
02:
03: import org.jgroups.ChannelException;
04: import org.jgroups.blocks.DistributedHashtable;
05: import org.jgroups.util.Util;
06:
07: /**
08: * Title: Java Groups Communications
09: * Description: Contact me at <a href="mailto:filip@filip.net">filip@filip.net</a>
10: * Copyright: Copyright (c) 2002
11: * Company: www.filip.net
12: * @author Filip Hanik
13: * @version 1.0
14: */
15: public class DistributedHashDeadLock {
16:
17: public DistributedHashDeadLock() {
18: }
19:
20: public static void main(String arg[]) throws ChannelException {
21: System.out.println("Starting hashtable");
22: String props = "UDP(mcast_addr=224.0.0.35;mcast_port=45566;ip_ttl=32;mcast_send_buf_size=150000;mcast_recv_buf_size=80000):"
23: + "PING(timeout=2000;num_initial_members=3):"
24: + "MERGE2:"
25: + "FD:"
26: + "VERIFY_SUSPECT(timeout=1500):"
27: + "pbcast.NAKACK(max_xmit_size=16000;gc_lag=1500;retransmit_timeout=600,1200,2400,4800):"
28: + "UNICAST(timeout=2000):"
29: + "pbcast.STABLE(desired_avg_gossip=20000):"
30: + "FRAG(frag_size=16000;down_thread=false;up_thread=false):"
31: + "pbcast.GMS(join_timeout=5000;join_retry_timeout=2000;shun=false;print_local_addr=true):"
32: + "pbcast.STATE_TRANSFER";
33:
34: DistributedHashtable distHash = new DistributedHashtable(
35: "ADMINT", null, props, 20000);
36: boolean odd = false;
37: int numberofelements = 1000;
38:
39: Util.sleep(5000);
40: System.out.println("size: " + distHash.size());
41: if (distHash.size() > 0)//The first instance counts up when numbers are even
42: { //The second when numbers are odd
43: odd = true;
44: }
45: boolean fillup = false;
46: if (!odd)
47: System.out.println("Loading hashtable with "
48: + numberofelements
49: + " elements. Don't start the other instance");
50: for (int i = 0; !odd && i < numberofelements; i++)//if the table isn't full we fill it
51: {
52: if (i % 50 == 0)
53: System.out.print(i + " ");
54: distHash.put("number" + i, new Integer(0));
55: fillup = true;
56: }
57: if (fillup)
58: System.out
59: .println("\n\nHashtable filled, you can now start the other instance\n");
60: System.out.println("initilising with odd: " + odd
61: + " and size " + distHash.size());
62: while (true) {
63: try {
64: System.out
65: .println("#######################################################");
66: Thread.sleep(10000);
67: int count = 0;
68: for (int i = 0; i < numberofelements; i++) {
69: int value = ((Integer) distHash.get("number" + i))
70: .intValue();
71: System.out.print(value + " ");
72: if (i % 50 == 0)
73: System.out.print("\n");
74: if (odd && (value % 2 != 0))//If the number is odd, and the instance is supposed to count odd numbers up
75: {
76: count++;
77: value++;
78: distHash.put("number" + i, new Integer(value));
79: continue;
80: }
81: if (!odd && (value % 2 == 0))//If the number is even, and the instance is supposed to count even numbers up
82: {
83: count++;
84: value++;
85: distHash.put("number" + i, new Integer(value));
86: continue;
87: }
88: }
89: System.out.println("\n" + odd
90: + " through all session, changed: " + count);
91:
92: } catch (Exception e) {
93: e.printStackTrace();
94: }
95: }
96:
97: }
98: }
|