Kraken
Kraken

Reputation: 24213

Forking a process

I have a process that goes to the database and gets data. The complexities and my questions are as follow:

Some data comes from one data source and the rest come from the other data source. I was wondering once i start a process, i can create the object where in i will dump all the data and then fork ( as in C language). an send each process to different data source.

Question 1 : If i do something like fork, it updates both the dumping of data simultaneously right? i.e. if parent process is getting data from source A and dumping in Object O, and chil process is getting from B and dumping in Object O only, the O gets populated simultaneously right? It will not create two objects one with data from A and other with data from B. Also, the efficiency of this process lies in the multiprocessor systems only?

Question 2: Is there anything like this in Java?

Thanks.

Upvotes: 1

Views: 287

Answers (2)

aviad
aviad

Reputation: 8278

You can try what @DaveHoves suggested. Another option I personally prefer when dealling with multiple source data loading/processing would be using ForkJoin framework. Please find good tutorial here.

Good Luck!

Upvotes: 3

DaveH
DaveH

Reputation: 7335

I'd say that the java equivalent to fork is java.lang.Thread. Have a look at here for a tutorial.

If I understand the question correctly, it looks like access to DataSource A would be via the main thread of your application while access to DataSource B would be handled by a separate thread. I'd be tempted to push access to both datasources in to separate threads, wait for them both to finish, ( see javadocs ), and then combine the results in to a single object ( Object O in your description above ).

Upvotes: 2

Related Questions