synchronize LinkedHashMap ejb transaction.RollbackException

synchronize LinkedHashMap ejb transaction.RollbackException - Java - Programmation

Marsh Posté le 27-03-2013 à 12:28:46    

Hello i have often  
A system exception occurred during an invocation on EJB TotoCacheBean, method: public void ...TotoCacheBean.refreshAlertCache() ...: ATTENTION: javax.ejb.EJBException: Transaction aborted
Caused by: javax.transaction.RollbackException at com.sun.jts.jta.TransactionManagerImpl.commit(TransactionManagerImpl.java:334)
 
   

Citation :

@Singleton
    @PersistenceContext(name = "persistence/popul", unitName = "popul" )
    @TransactionAttribute(value = TransactionAttributeType.SUPPORTS)
    @ConcurrencyManagement(ConcurrencyManagementType.BEAN)
    @Startup
    public class TotoCacheBean
    {
     private final ReadWriteLock lock = new ReentrantReadWriteLock();
 
 @Inject
 private MessageDAO messageDAO;
 
 public enum Type
 {
  ALERT, GLOBAL
 };
 
 private Map<Type, TotoCache> cacheStorage;
 
 @PostConstruct
 public void postConstruct() throws DAOException
 {
  refreshAlertCache();
  refreshGlobalCache();
 }
 
 @Schedule(second = "*/20", minute = "*", hour = "*", persistent = false)
 public void refreshAlertCache() throws DAOException
 {
  refreshCache(Type.ALERT);
 }
 
 @Schedule(second = "10", minute = "*", hour = "*", persistent = false)
 public void refreshGlobalCache() throws DAOException
 {
  refreshCache(Type.GLOBAL);
 }  
 
 private void refreshCache(Type type) throws DAOException
 {
  Date now = DateTools.getDate();
  LinkedHashMap<String, LinkedHashMap<String, ActMessDTO>> messages = messageDAO.getActMessSorted(now, (type == Type.ALERT));
  setCache(type, new TotoCache(messages, now));
 }
 
 
 public TotoCache getCache(Type type)
 {
  lock.readLock().lock();
 
  try
  {
   return getCacheStorage().get(type);
  }
  finally
  {
   lock.readLock().unlock();
  }
 }
 
 private void setCache(Type type, TotoCache cache)
 {
  lock.writeLock().lock();
 
  try
  {
   getCacheStorage().put(type, cache);
  }
  finally
  {
   lock.writeLock().unlock();
  }
 }
 
 private Map<Type, TotoCache> getCacheStorage()
 {
  if (this.cacheStorage == null)
   this.cacheStorage = new HashMap<Type, TotoCache>();
 
  return this.cacheStorage;
 }
 
}


 
Have you some ideas to resolve the issue? The LinkedHashMap is not synchronized but i prefer not to change it because it will change more than 10 classes. but if it 's the reason i will do it.  
Or the probleme is the use of ReadWriteLock? thanks for your tricks
 

Reply

Marsh Posté le 27-03-2013 à 12:28:46   

Reply

Marsh Posté le 27-03-2013 à 13:41:45    

Bonjour,
 
Ce serait sympa que tu traduises ton texte original en mauvais anglais avant de poster sur un forum francophone. (+balise "code" ). Merci.


---------------
http://devicenotready.com/ - Informatique et autres bizarreries
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed