Native thread behaviour
Hi guys...
Playing with native methods, I have created a very basic program that
creates a TCP/IP socket from Java by using the corresponding C call (i.e.,
socket()).
My code (excluding error handling parts) is something like:
// File NativeSocketApplication.java
public class NativeSocketApplication
{
private static NativeSocket socket;
public static void main(String args[])
{
System.out.print("\n\nApplication started");
socket = new NativeSocket();
System.out.print("\n\nNativeSocket() returned
successfully.");
}
}
// File NativeSocket.java
public class NativeSocket()
{
public NativeSocket()
{
System.out.print("\n\nCalling native method");
nativeSocketCreate(AF_INET, SOCK_DGRAM, PF_INET);
}
private void nativeSocketCreate(int family, int type, int protocol)
{
// Calls Linux socket(family, type, protocol) function
}
}
// File native_socket.c
{
// My nativeSocketCreate function with JNI syntactic sugar
JNIEXPORT void JNICALL Java_NativeSocket_nativeSocketCreate
(JNIEnv *env, jobject jthis, jint family, jint type, jint
protocol)
{
printf("\n\nCreating native socket...");
socket(family, protocol, data);
}
}
Very simple, BUT: When I run the program under windows, as expected, I get
the following output:
Application started
Calling native method
Creating native socket...
NativeSocket() returned successfully.
which is reasonable (I use only one thread).
In Linux, things are not doing that well. Using either JDK 1.1.7 or JDK 1.2,
I get
Application started
Calling native method
NativeSocket() returned successfully.
==> Creating native socket... (!!!)
In JDK 1.1.7, the last message is even printed after the Unix prompt(!)...
Is this just a problem related to interaction with the output (can't be that
the order of execution is altered, surely!), or does it mean potential
synchronisation problems?
Thanks,
Dimitris
PS: Sorry if you have seen this message before, but I haven't received it
(contrary to what happened with my other postings). It was originally posted
a few days ago, and since then I receive other people's mails, but not mine.
--
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: Memory problems
Nathan, I read your reply to Benjamin Edelman, where you asked the question >2) Check the contents of /proc/meminfo to make sure you have all the >memory and swap you think you do (you do boot with the linux "mem=" >option, right?). I'm new to the Linux environment, running Blackdown jdk1.1.7v3 on an i386. I'm not sure whether or not I'm booting with the linux "mem=" option. 1. What's the reason for doing so? 2. How do I set up the boot operation to do so? >Benjamin Edelman wrote: > > > > I'm running JDK 1.1.7v3 on an i386 running RedHat 5.2. The JDK has a nasty > > habit of bailing out with an out of memory error before my machine has > > actualy run out of memory > >Some things to try: > >1) Make sure you're not out of memory due to other big processes >running. > >2) Check the contents of /proc/meminfo to make sure you have all the >memory and swap you think you do (you do boot with the linux "mem=" >option, right?). > >3) Type "ulimit -a" into bash to see if you've got a "max memory size" >or "data seg size" other than unlimited. > >Nathan -- Roland Silver <[EMAIL PROTECTED]> -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: Memory problems
Roland Silver wrote: > > Nathan, > I read your reply to Benjamin Edelman, where you asked the question > > >2) Check the contents of /proc/meminfo to make sure you have all the > >memory and swap you think you do (you do boot with the linux "mem=" > >option, right?). > > I'm new to the Linux environment, running Blackdown jdk1.1.7v3 on an i386. > I'm not sure whether or not I'm booting with the linux "mem=" option. > 1. What's the reason for doing so? > 2. How do I set up the boot operation to do so? Until the 2.2 kernel, Linux needs help discovering more than 64M of RAM... I don't know why. Assuming you boot using LILO, you'll have a lilo.conf that contains lines looking something like this: image=/boot/vmlinuz-2.2.5-15 label=linux root=/dev/hda3 read-only This describes a particular kernel disk image and some other things needed to boot. You can add a parameter that specifies the memory size in the indented lines: mem=128m (or however much you have). But it's a good idea before you do that to create an alternative entry in LILO to *try it* first. For example, add some lines that copy the existing lines, with a different label and with the new info: image=/boot/vmlinuz-2.2.5-15 label=newlinux root=/dev/hda3 mem=128m read-only run /sbin/lilo to process your new configuration. Reboot... when you get the LILO prompt, answer "newlinux" instead of letting it use the default (which is presumably "linux"). Another way to try the same experiment is not to mess with lilo.conf, but answer "linux mem=128m" when you get the LILO prompt at boot time. Anyway... if everything works - the system comes up and you seem to have your memory, you can add the "mem=" to your default LILO entries, run /sbin/lilo, and you're in business. It would probably be a good idea to read http://www.linuxdoc.org/HOWTO/mini/LILO.html, rather than just relying on my sketchy instructions here. Hope this helps... Nathan -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
Re: Memory problems
This is not necessary with the 2.2 kernel. I am not sure what kernel you are using. I am at RH 6.0 and /proc/meminfo has: total:used:free: shared: buffers: cached: Mem: 197484544 191668224 5816320 54882304 58417152 66740224 Swap: 2549432320 254943232 MemTotal:192856 kB MemFree: 5680 kB MemShared:53596 kB Buffers: 57048 kB Cached: 65176 kB SwapTotal: 248968 kB SwapFree:248968 kB I have 192MB and here is lilo.conf: boot=/dev/sdb2 map=/boot/map install=/boot/boot.b #linear #prompt #timeout=50 image=/boot/vmlinuz-2.2.5-15 label=linux root=/dev/sdb2 initrd=/boot/initrd-2.2.5-15.img read-only #other=/dev/sda5 # label=dos # table=/dev/sda This used to be an issue with kernels before 2.2. john On 05-Sep-99 Nathan Meyers wrote: > Roland Silver wrote: >> >> Nathan, >> I read your reply to Benjamin Edelman, where you asked the question >> >> >2) Check the contents of /proc/meminfo to make sure you have all the >> >memory and swap you think you do (you do boot with the linux "mem=" >> >option, right?). >> >> I'm new to the Linux environment, running Blackdown jdk1.1.7v3 on an i386. >> I'm not sure whether or not I'm booting with the linux "mem=" option. >> 1. What's the reason for doing so? >> 2. How do I set up the boot operation to do so? > > Until the 2.2 kernel, Linux needs help discovering more than 64M of > RAM... I don't know why. Assuming you boot using LILO, you'll have a > lilo.conf that contains lines looking something like this: > > image=/boot/vmlinuz-2.2.5-15 > label=linux > root=/dev/hda3 > read-only > > This describes a particular kernel disk image and some other things > needed to boot. You can add a parameter that specifies the memory size > in the indented lines: > > mem=128m > > (or however much you have). But it's a good idea before you do that to > create an alternative entry in LILO to *try it* first. For example, add > some lines that copy the existing lines, with a different label and with > the new info: > > image=/boot/vmlinuz-2.2.5-15 > label=newlinux > root=/dev/hda3 > mem=128m > read-only > > run /sbin/lilo to process your new configuration. Reboot... when you get > the LILO prompt, answer "newlinux" instead of letting it use the default > (which is presumably "linux"). > > > Another way to try the same experiment is not to mess with lilo.conf, > but answer "linux mem=128m" when you get the LILO prompt at boot time. > > > Anyway... if everything works - the system comes up and you seem to have > your memory, you can add the "mem=" to your default LILO entries, run > /sbin/lilo, and you're in business. > > > It would probably be a good idea to read > http://www.linuxdoc.org/HOWTO/mini/LILO.html, rather than just relying > on my sketchy instructions here. > > > Hope this helps... > > > Nathan > > > -- > To UNSUBSCRIBE, email to [EMAIL PROTECTED] > with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED] -- E-Mail: John N. Alegre <[EMAIL PROTECTED]> Date: 05-Sep-99 Time: 13:26:44 This message was sent by XFMail -- -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
