Thread: [tcljava-user] Some questions ( no HTML now )
Brought to you by:
mdejong
From: Jesus M. S. Jr. <jm...@ih...> - 2001-05-20 03:19:42
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 My apologies to everyone on the list ( and to Mo ). I was using the mail gateway to my mailbox at work, and apparently there was no option to turn on or off HTML formatting ... and all the while I thought things were being sent as plain text. So I am sending the questions again using a new subscription with my home e-mail address. I am a Java developer, with some basic knowledge of Tcl. I am intersted mainly in Tcl calling Java methods. In the end, I want to use it with Vignette's StoryServer. I have recently downloaded and tried TclBlend on both linux and Solaris, and they worked as expected. However, I still have some few questions that I cannot find in the FAQ. 1) In the man page for "package require java", it said that "Tcl will create a JVM in Tcl's process space". What does this exactly mean? In both linux and solaris, when I call "package require java" in a Tcl shell, I cannot see a java process runnning ( even with linux's "ps axf" command ). To be honest, I was expecting a Java process somehow as a child of the tcl process, but that does not seem to be the case. What are the differences ( and implications ) between what I was expecting and what tclblend actually does? D.J.: You mentioned that they would show as child processes with linux's "ps" command. However, I tried that several times .... within a tclsh just after "package require java", after a "[java::new ]" .... and I do not see such child processes. 2) How many JVMs are created within the lifetime of the tcl process? For example, if multiple tcl scripts have a "package require java" as the first line of each of the script, will each call to "package require java" create a new JVM? 3) This last question maybe a bit offtopic ... but with StoryServer ( SS ), a SS template can be called multiple times by different browsers at the same time ( multi-threaded ). Within Vignette's installation page for TclBlend, the TclBlend binary distribution does not seem to be any different ( e.g.: no proprietary extension seems to be required or installed to make TclBlend work with SS ). With this regard ( threading ), will each call to the templatec reate a separate JVM? Probably a better way to ask question [3] is: If I was doing threading in Tcl, will each thread run its own JVM? Thanks in advance, John Salvo -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.4 (GNU/Linux) Comment: For info see http://www.gnupg.org iEYEARECAAYFAjsHOM8ACgkQAvd5SY4qWYytlQCfbqVimwODLi4TPmN1+/vbRf8g Rg8AnisscblwHlF/x65NwXW7K1+38dqU =VsBu -----END PGP SIGNATURE----- |
From: D. J. H. <dha...@mi...> - 2001-05-20 16:57:52
|
"Jesus M. Salvo Jr." wrote: > D.J.: You mentioned that they would show as child processes with linux's "ps" > command. However, I tried that several times .... within a tclsh just after > "package require java", after a "[java::new ]" .... and I do not see such > child processes. Only if you start creating/running threads in the Java code. E.g., --------- TestThread.java --------------- public class TestThread implements Runnable { private boolean flag_ = true; private boolean interrupted_ = false; public void run() { while( !interrupted_ ) { System.out.println(flag_ ? "Tick" : "Tock"); System.out.flush(); flag_ = !flag_; try { Thread.sleep(1000L); } catch( InterruptedException ex ) { interrupted_ = true; } } } } ------------------------------------------ javac TestThread.java jtclsh package require java set tt [java::new Thread [java::new TestThread]] $tt start And now, on Linux, if your JVM is set to use native threads, you'll see a child process off your jtclsh process. If your JVM is set to use green threads, you will still only see one process. (on linux, green threads are a *lot* less resource intensive on a single-processor box). Hopefully Mo can answer your other questions, but some of it can really only be answered through tests. For instance, create two interps in tclsh, package require java into both of them, and then do something like: java::call System setProperty interp1prop Hi System properties are exclusive per VM, so if, in fact, there were two VMs created, the second interp would not be able to find the property you set in the first interp. With TclJava 1.2.6, this does not appear to be the case: % java::call System setProperty interp1prop Hi % % set ni [interp create] interp0 % $ni eval "package require java" 1.2.6 % $ni eval {java::call System getProperty interp1prop} Hi I don't have a thread-enabled Tcl to perform a similar test with threads, but perhaps you could do so with the interp that comes with Vignette? Hope this helps, -=- D. J. |
From: Mo D. <md...@cy...> - 2001-05-20 21:03:39
|
On Sun, 20 May 2001, Jesus M. Salvo Jr. wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > My apologies to everyone on the list ( and to Mo ). I was using the mail > gateway to my mailbox at work, and apparently there was no option to turn on > or off HTML formatting ... and all the while I thought things were being sent > as plain text. So I am sending the questions again using a new subscription > with my home e-mail address. > > I am a Java developer, with some basic knowledge of Tcl. I am intersted > mainly in Tcl calling Java methods. In the end, I want to use it with > Vignette's StoryServer. > > I have recently downloaded and tried TclBlend on both linux and Solaris, and > they worked as expected. > > However, I still have some few questions that I cannot find in the FAQ. > > 1) In the man page for "package require java", it said that "Tcl will create > a JVM in Tcl's process space". What does this exactly mean? In both linux and > solaris, when I call "package require java" in a Tcl shell, I cannot see a > java process runnning ( even with linux's "ps axf" command ). That is because the Tcl process loads the JVM shared libs into the Tcl process and creates a JVM in the same process. There would only be one process at that point. > To be honest, I > was expecting a Java process somehow as a child of the tcl process, but that > does not seem to be the case. What are the differences ( and implications ) > between what I was expecting and what tclblend actually does? Using two processes would mean that Tcl <-> Java communication would be slow since IPC would be required. Also, why would you want to do that when the JNI api is already a standard part of Java? > D.J.: You mentioned that they would show as child processes with linux's "ps" > command. However, I tried that several times .... within a tclsh just after > "package require java", after a "[java::new ]" .... and I do not see such > child processes. > > > 2) How many JVMs are created within the lifetime of the tcl process? For > example, if multiple tcl scripts have a "package require java" as the first > line of each of the script, will each call to "package require java" create a > new JVM? There is only 1 JVM. > 3) This last question maybe a bit offtopic ... but with StoryServer ( SS ), a > SS template can be called multiple times by different browsers at the same > time ( multi-threaded ). Within Vignette's installation page for TclBlend, > the TclBlend binary distribution does not seem to be any different ( e.g.: no > proprietary extension seems to be required or installed to make TclBlend work > with SS ). With this regard ( threading ), will each call to the templatec > reate a separate JVM? > > Probably a better way to ask question [3] is: If I was doing threading in > Tcl, will each thread run its own JVM? There is only 1 JVM, multiple threads can talk to the JVM in a thread safe way. If you are dealing with threads, the 1.3 dev version in the CVS is the only way to go. It includes a lot of threading changes that fix some of the more nasty problems in the 1.2 series. Of course, 1.3 is not yet ready for prime time. More testing of the thread changes is needed before it can be called "stable". If folks are interested in speeding up the "stable" release, by all means get involved in the 1.3 development process. Mo |