Link to home
Create AccountLog in
Avatar of Jay Roy
Jay RoyFlag for United States of America

asked on

dividing data among threads

hi guys

Needed some help with code
I have this so far

 
int numberOfThreads = 5;

for(int i=0; i < numberOfThreads; i++){ 				
Callable<List<CustomerVO>> task = new Callable<List<CustomerVO>>(){ 
public List<CustomerVO> call(){				
String rowCount = executeQuery("select count(*) from CUSTOMER"); //returns 6000
List<CustomerVO> resultList = executeQuery("select * from customer",new ArrayList())
.subList(beginCount, endCount);
return 	resultList;
	}
};
processMemory(resultList); 
}

Open in new window

//my requirment is if rowCount returns 6000 rows i want to distribute it among the 5 threads in the forloop.
 
so for Thread1 i will have
List<CustomerVO> resultList = executeQuery("select * from customer",new ArrayList()).subList(beginCount, endCount);
beginCount =0 and endCount = 12000

Thread2
List<CustomerVO> resultList = executeQuery("select * from customer",new ArrayList()).subList(beginCount, endCount);
beginCount =1200 and endCount = 2400

Thread3
List<CustomerVO> resultList = executeQuery("select * from customer",new ArrayList()).subList(beginCount, endCount);
beginCount =2400 and endCount = 3600

Thread4
List<CustomerVO> resultList = executeQuery("select * from customer",new ArrayList()).subList(beginCount, endCount);
beginCount =3600 and endCount = 4800

Thread5
List<CustomerVO> resultList = executeQuery("select * from customer",new ArrayList()).subList(beginCount, endCount);
beginCount =4800 and endCount = 6000

How can i modify my beginCount and endCount within my for loop?

Any help will be greatly appreciated

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

You've proved multithreading enhances performance have you? If so, how did you benchmark it?
Avatar of Jay Roy

ASKER

>> If so, how did you benchmark it?
benchmarked it using visualvm thread profiler, In our scenario we had 900000 rows of dataprocessing (from database table-select - process - update data) distributed among 6 threads finishes in < 5 minutes.
With a single thread it takes around 30 minutes :)
that was our benchmarking.
That's good - just checking ;) More tomorrow
ASKER CERTIFIED SOLUTION
Avatar of Valeri
Valeri
Flag of Bulgaria image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.