I am having problem with calling both Parallel::ForkManager and Inline::Java at the same time. Specifically, if I call the Inline::Java with the JNI => 1 option (which I have to), then the fork process doesn’t come back to the parent. Here are the codes:
use Parallel::ForkManager;
##### Calling Inline::Java #####
use Inline Java => <<END, JNI => 1;
END
###### End of Inline::Java #####
my $pm = Parallel::ForkManager->new(2);
for my $i (0..1) {
$pm->start and next;
print "Inside process $i\n";
$pm->finish;
}
$pm->wait_all_children;
print "Back to Parent.\n";
If I run this program, it goes into the child processes but never comes back to the parent. If I remove the 3 lines between the comments, it runs fine. If I change the JNI => 1 to JNI => 0 (not that I’m allowed to change that parameter for my purpose), then there is an error message of Lost connection with Java virtual machine at /usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/Inline/Java.pm line 975.
Does anyone have a clue how to resolve the conflict? I also have to call the Inline::Java before the parallel process so using require after parallel is done is not an option. Thx!
Every child is talking over the same socket, which leads to the VM receiving jibberish.
You need to delay making a connection to the VM so that it’s done in the children instead of it the parent.
You could move all thing Inline::Java-related into another module, then use
require Child;(notuse Child;) afterstart.If you need to use Inline::Java before launching the child, do it in a different process.