|
On 22/07/2005, at 7:07 PM, Larry Ducie wrote:
How does this work with multi-threading though? I mean, you can have many threads running within java, but the iSeries creates a BCI job for each thread (I believe).
Not true. A Batch-Immediate (BCI) job is the result of using one of the spawn() family of APIs. spawn() is functionally equivalent to the fork() and exec() combination so common in Unix-land. A spawned job is a separate job just like fork() creates a separate process. Spawn can be used to create the illusion of multi-threading at an application level but then so can SBMJOB.
fork() tends to result in schizoid programs that behave differently depending on whether they run in the parent process or the child process. exec() helps avoid that by allowing the forked process to load and run a different program.
Threads however are not spawned but are started by pthread_create(). These are true kernel threads and run in the same job as the job that created them. There is a main thread plus 0 or more child threads each of which can in turn start additional threads. Threads can only run in a job that is capable of supporting multiple threads which means a Batch (BCH) job that has the ALWMLTTHD attribute set to *YES or a BCI job that has the SPAWN_SETTHREAD_NP set on. Thus there is a link between threads and batch jobs but threads are not implemented as batch jobs.
One of the few decent books on Posix threads is "Programming with POSIX Threads" by David R. Butenhof.
Does the main thread run within the same job as the JVM (and RPG program) but all other threads run as BCI jobs along-side it?
Depends on how the JVM was started. If started in the current job (via JNI) then it runs in parallel with the main thread. Other threads, whether application threads or JVM threads, run in the same job.
If started via RUNJVA or QSHELL then the JVM is in a separate BCI job and any Java threads, including the garbage collector thread, run in that other job. Application threads run in the parent job.
Also, what about the garbage collector? Doesn't that run in a separate thread (job) too?
Garbage collection runs as a thread in the same job as the JVM. Regards, Simon Coulter. -------------------------------------------------------------------- FlyByNight Software AS/400 Technical Specialists http://www.flybynight.com.au/ Phone: +61 3 9419 0175 Mobile: +61 0411 091 400 /"\ Fax: +61 3 9419 0175 \ / X ASCII Ribbon campaign against HTML E-Mail / \ --------------------------------------------------------------------
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.