简体   繁体   English

分叉过程

[英]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). 我想知道一旦开始一个过程,就可以创建一个对象,在该对象中我将转储所有数据,然后分叉(如C语言)。 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? 问题1:如果我做类似fork的操作,它会同时更新两个数据转储,对吗? ie 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? 即,如果父进程从源A获取数据并转储到对象O中,而chil进程从B获取数据并仅转储到对象O中,那么O会同时填充吗? 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? 它不会创建两个对象,一个对象来自A的数据,另一个对象来自B的数据。而且,此过程的效率仅取决于多处理器系统吗?

Question 2: Is there anything like this in Java? 问题2:Java中是否有类似的东西?

Thanks. 谢谢。

You can try what @DaveHoves suggested. 您可以尝试@DaveHoves的建议。 Another option I personally prefer when dealling with multiple source data loading/processing would be using ForkJoin framework. 当处理多个源数据加载/处理时,我个人更喜欢的另一个选择是使用ForkJoin框架。 Please find good tutorial here . 在这里找到好的教程。

Good Luck! 祝好运!

I'd say that the java equivalent to fork is java.lang.Thread . 我说相当于fork的java是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. 如果我正确理解了这个问题,则似乎可以通过应用程序的主线程访问DataSource A,而对DataSource B的访问将由单独的线程处理。 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 ). 我很想将对两个数据源的访问推送到单独的线程中,等待它们都完成(请参阅javadocs ),然后将结果合并到单个对象中(在上面的描述中为Object O)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM