Jagadeesh M
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","12321 34234","12 34214","12 34214","12 342134"};
String localeCd = "de-DE";
System.out.println("Length : "+lineId.length);
for(int i = 0 ; i < lineId.length ;i++){
try {
ServiceInvocation serviceInv = ServiceInvocation.getInsta nce();
PDNAGlobalLinkPort proxy = (PDNAGlobalLinkPort)servic eInv.creat e(PDNAGlob alLinkPort .class);
ApproveTranslationRequestD TO reqDTO = new ApproveTranslationRequestD TO();
reqDTO.setRequestContextBe an(Mercury Util.build RequestCon text());
reqDTO.setItemId(new Long(lineId[i]).longValue( ));
reqDTO.setLocalCode(locale Cd);
boolean success = proxy.approveTranslation(r eqDTO);
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("Except ion -->> "+e.getMessage()+ ">> has been generated");
}
}
System.out.println(">>>>>> >>>>>>DONE <<<<<<<<<< <<<<<");
}
}
Is this possible?
Thank you
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","12321
String localeCd = "de-DE";
System.out.println("Length
for(int i = 0 ; i < lineId.length ;i++){
try {
ServiceInvocation serviceInv = ServiceInvocation.getInsta
PDNAGlobalLinkPort proxy = (PDNAGlobalLinkPort)servic
ApproveTranslationRequestD
reqDTO.setRequestContextBe
reqDTO.setItemId(new Long(lineId[i]).longValue(
reqDTO.setLocalCode(locale
boolean success = proxy.approveTranslation(r
if(success)
System.out.println(i+" "+lineId[i] + " " + localeCd +" -->>> approved");
else
System.out.println(lineId[
}catch (Exception e) {
System.out.println("Except
}
}
System.out.println(">>>>>>
}
}
Is this possible?
Thank you
What makes you think that multi-threading will make it faster? It's more likely to slow it down
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
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.