Link to home
Start Free TrialLog in
Avatar of Jagadeesh M
Jagadeesh MFlag for United States of America

asked on

Convert code to Multi threading

Hi -

The below code published some content into the database. I need to turn this code into a mutithreaded code so that the operation happens fastly. And the reason i need to have this is because my lineid[] contains more than 5000+ values.

public class PublishPropertyObjects {
             public static void main(String[] args) {
              
              String lineId[]={"4983462","1232134234","1234214","1234214","12342134"};             
              
              String localeCd = "de-DE";
                System.out.println("Length : "+lineId.length);
          for(int i = 0 ; i < lineId.length ;i++){
          try {
                                  
                      ServiceInvocation serviceInv = ServiceInvocation.getInstance();
                      PDNAGlobalLinkPort proxy = (PDNAGlobalLinkPort)serviceInv.create(PDNAGlobalLinkPort.class);
               
                      ApproveTranslationRequestDTO reqDTO = new ApproveTranslationRequestDTO();
                      reqDTO.setRequestContextBean(MercuryUtil.buildRequestContext());
                reqDTO.setItemId(new Long(lineId[i]).longValue());
                reqDTO.setLocalCode(localeCd);
                boolean success = proxy.approveTranslation(reqDTO);
               
                if(success)
                      System.out.println(i+"  "+lineId[i] + " " + localeCd +" -->>> approved");
                else
                      System.out.println(lineId[i] + " " + localeCd +" failed to approve");
                      
                }catch (Exception e) {
                      System.out.println("Exception -->> "+e.getMessage()+ ">> has been generated");
                      
                }
                }
          
                System.out.println(">>>>>>>>>>>>DONE<<<<<<<<<<<<<<<");
                
                
          }
    }


Is this possible?

Thank you
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

What makes you think that multi-threading will make it faster? It's more likely to slow it down
Avatar of Jagadeesh M

ASKER

my code was simply calling the service by sending the lineids one after the other. Imagine if i have 5000 records....while the service is executing one lineid why shouldn't i call the same service again and for a second one....becoz my request is independent of the responses.
You could give it a try but it's not likely to speed things up
could you please explain why?
Let's turn that around first shall we - can you say why you think it will speed things up?
ASKER CERTIFIED SOLUTION
Avatar of Bart Cremers
Bart Cremers
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial