java - How to call SOAP Web Services in many threads in Wildfly? -


i have external soap web service receive text message sms gate. receiving operation blocking operation waits few seconds (i can configure it) , returns message or null.

i want receive messages multiple gates. in order create multiple threads (managed threadpoolexecutor). use jpa , cdi inside use managedthreadfactory create threads.

the simplified version of code looks follows:

import org.slf4j.logger; import org.slf4j.loggerfactory; import javax.annotation.postconstruct; import javax.annotation.resource; import javax.ejb.singleton; import javax.ejb.startup; import javax.enterprise.concurrent.managedthreadfactory; import javax.inject.inject; import java.util.list; import java.util.concurrent.synchronousqueue; import java.util.concurrent.threadpoolexecutor; import java.util.concurrent.timeunit;  @singleton @startup public class testbean {     private static final int core_pool_size = 0;     private static final long keep_alive_time = 60l;      private logger logger = loggerfactory.getlogger(getclass());      @resource     private managedthreadfactory managedthreadfactory;     private threadpoolexecutor managedthreadexecutor;      private list<string> sourcesofmessages;     private soapmessagesource soapmessagesource;      @inject     public testbean(@somequalifier list<string> sourcesofmessages, soapmessagesource soapmessagesource) {         this.sourcesofmessages = sourcesofmessages;         this.soapmessagesource = soapmessagesource;     }      @postconstruct     public void startreceivingmessagesfromallsources() {         sourcesofmessages.stream()                 .foreach(this::startnewreceivinginnewthread);     }      private void startnewreceivinginnewthread(string sourceofmessages) {         getmanagedthreadexecutor().execute(() -> startreceivingmessagesfromsource(sourceofmessages));     }      private void startreceivingmessagesfromsource(string sourceofmessages) {         while (true) {             tryreceivemessage(sourceofmessages);         }     }      private void tryreceivemessage(string sourceofmessages) {         logger.info("receiving messages source {} in thread {}, {}", sourceofmessages, thread.currentthread().getname(), managedthreadexecutor);          receivedmessage message = soapmessagesource.getmessage(sourceofmessages); // blocking operation; waits 10 seconds message         if (message != null) {             logger.info("received message {}", message);             // requires jpa here         } else {             logger.info("no message in {}", sourceofmessages);         }     }      private threadpoolexecutor getmanagedthreadexecutor() {         if (managedthreadexecutor == null) {             managedthreadexecutor = new threadpoolexecutor(core_pool_size, integer.max_value,                     keep_alive_time, timeunit.seconds,                     new synchronousqueue<>(),                     managedthreadfactory);         }         return managedthreadexecutor;     } } 

is method of using theads call multiple soap web services @ same time correct? have clues how improve it? why threads stay alive after package bean undeployed?


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -