0

I plan to have a broker topic and have multiple default message listeners or simple message listeners. All the listeners execute the same code.

  1. Is each listener code execution independent of another. What I am trying to ask is, if there will be a conflict among listeners when accessing the same methods ?

I kind of what them to work like a multi threaded execution. I am using JMS and activemq as broker.

Some code to understand : Each listener will call this method "event processing" sending the event. This method will in turn call other methods. The handle method will in turn call other methods.

private void eventProcessing(final Event Event){
        try {
                if(Event.isDatafileTransaction()){
                final EventDatafileTransaction datafileTransaction = Event.getDatafileTransaction();

                            final List<Events> transactions = getDatafileTransactions(datafileTransaction);
                            final List<AcEventRecordOperation> recordOperations = getTransactionsAsListOfRecordOperations(datafileTransaction, transactions);

                            if (recordOperations != null  && recordOperations.size() > 0) {

                                    recordOperationListener.handle(recordOperations);

                        }

                }
        }  catch (Throwable t) {

        }

    }
africandrogba
  • 334
  • 1
  • 3
  • 21
  • It is hard to tell without a more detailed code snippets, but the basic multi threading and concurrency still applies to you. So assuming the eventProcessing method is on a class and being called by multiple listeners and the Event object passed in by each listeners are unique to individual listeners, I think you are pretty thread-safe here – Irwan Hendra Sep 27 '17 at 01:46

1 Answers1

0

Your listener must be thread-safe - no fields (class-level variables) or they must be protected with synchronization.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179