By refactoring the above code to retry a configurable number of times and by 
randomizing the time to wait between retries, I was able to get the behavior I 
expected.  Essentially, this code takes a concurrent event, and makes it not 
concurrent (avoiding the distributed deadlock situation altogether).

The refactored code:

  |     public void test()
  |     throws Exception
  |     {
  |         _cache.startService();
  | 
  |         try
  |         {
  | 
  |             // Try to insert into the cache a maximum of 2 times.
  |             int retryCount = 2;
  | 
  |             for (int i = 0; i < retryCount; i++)
  |             {
  |                 try
  |                 {
  |                     putInCache("key", _value);
  |                 }
  |                 catch (AlreadyBound ab)
  |                 {
  |                     throw ab;
  |                 }
  |                 catch (Exception e)
  |                 {
  |                     System.out.println();
  |                     System.out.println("===== Try #" + i + " 
=============================");
  |                     e.printStackTrace(System.out);
  |                     
System.out.println("==========================================");
  |                     System.out.println();
  | 
  |                     // Wait at least 100 milliseconds.
  |                     Thread.sleep(_random.nextInt(4900) + 100);
  | 
  |                     continue;
  |                 }
  | 
  |                 break;
  |             }
  |         }
  |         catch (Throwable t)
  |         {
  |             t.printStackTrace(System.out);
  |             System.out.println();
  |         }
  |         finally
  |         {
  |             System.out.println();
  |             System.out.println("Done.");
  |             System.out.println();
  |         }
  |     }
  | 
  |     private void putInCache(String key, String value)
  |     throws Exception
  |     {
  |         UserTransaction tx =
  |             new DummyUserTransaction(DummyTransactionManager.getInstance());
  | 
  |         tx.begin();
  | 
  |         Object previous = _cache.put("aom", "key", _value);
  | 
  |         if (previous != null)
  |         {
  |             tx.rollback();
  | 
  |             throw new AlreadyBound();
  |         }
  |         else
  |         {
  |             tx.commit();
  |         }
  |     }
  | 
Anyone else have other ideas on how to handle distributed deadlock situations?

View the original post : 
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3855027#3855027

Reply to the post : 
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3855027


-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to