multithreading - java multithreding , creating object for each thread -



multithreading - java multithreding , creating object for each thread -

i have 2 class callispsubscriberdump (this class reads database total no of process id , each process id calls ispsubscriberdump class create file) , ispsubscriberdump (used create isp subscriber dump file sent network provioning ). using executor service create multiple threads , passing process id ispsubscriberdump in constructor , in approach have create many objects many threads running. process working fine. have run thread each process id , there other way in can create single object , crate multiple objects?

public class callispsubscriberdump { public void createfile() { list<integer> totalid = new arraylist<integer>(); list<string> dataflag = new arraylist<string>(); //reading process id , dataflag database , populating in list seek { if (totalid.size() == 0) { throw new exception("no process id found isp dump"); } else { // max_thraed max limit of threads int maxthred = totalid.size() < integer.parseint(loggererator.getproperty("max_thraed")) ? totalid.size() : integer.parseint(loggererator.getproperty("max_thraed")); executorservice executor = executors.newfixedthreadpool(maxthred); (int cnt = 0; cnt < totalid.size(); cnt++) { //for particular thread assigning particular process create n object of ispsubscriberdump n thread , assign process id in constructor executor.execute(new ispsubscriberdump(totalid.get(cnt),dataflag.get(cnt))); } executor.shutdown(); while (!executor.isterminated()) { } system.out.println("finished threads"); } } grab (exception e) { e.printstacktrace(); } public class ispsubscriberdump implements runnable { private int processid; private string dataflag; public ispsubscriberdump(int processid,string dataflag){ this.processid=processid; this.dataflag=dataflag; } public void run() { // file creation createfile(); } createfile() { int currentprocessid=processid; string currentdataflag= dataflag; // file creation , provising happened here using currentprocessid , currentdataflag } }

tl;dr

"is there other way in can create single object , crate multiple objects?"

maybe can utilize singleton/factory class.

java multithreading executorservice

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -