Java 5 threads in linux

Hi,
I am using the following java version in Linux
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Server VM (build 1.5.0_06-b05, mixed mode)
Threads are created using the source code:
private static ExecutorService thPool = Executors.newFixedThreadPool(5);
My question is how threads are created in linux using the mentioned runtime.
1. Does the code line above create 5 linux native threads (process)?
2. Does it create java threads? Don't know if java and native threads are same.
3. If answer of the question 1 is "NO" then does one native linux threads for java runtime do all the concurrent execution?
Please explain. Any documents on java threads in Linux for java 5?
Thanks in advance
Sunny

What is your problem that makes you worry aboutthose things?
Java for Linux uses NPTL thread library for itsthread.
Browse the link to see what I wanted:
http://groups.google.com/group/comp.lang.java.programm
er/browse_thread/thread/2848feac5cd52151/9b6f6bf226ca9
ef0?lnk=raot#9b6f6bf226ca9ef0reply 1, again. I don't understand your problem yet.

Similar Messages

  • Maximum simultaneous opened files in a java thread on linux 1.4.20

    Hello,
    It seems like a maximum of 1024 files can be opened by a processus on linux (in java, a thread is a linux processus).
    Is it possible to change this value, or has it been set at the JVM compilation?
    I created a nio server, and one thread is to manage thousands of connections. For the moment I can't pass 1010 connections.
    As a fast test, I created the following source :
    public class MaxOpenedFilesTest {
    /** Creates a new instance of MaxOpenedFilesTest */
    public MaxOpenedFilesTest() {
    * @param args the command line arguments
    public static void main(String[] args) {
    File f = new File("/home/greg/a.out");
    FileInputStream[] stream = new FileInputStream[2000];
    try {
    for (int i=0; i<stream.length; i++) {
    stream[i] = new FileInputStream(f);
    System.out.println(i+" files opened");
    catch (Exception e) {
    System.out.println("ERROR : "+e);
    e.printStackTrace();
    This test throws an IOException at 1019 files opened : Too many opened files...
    I have tested a lot of things. I even recompiled the linux kernel. Changed the NR_OPEN, OPEN_MAX, __FD_SETSIZE, etc... Still don't work.
    I havve set the global maximum file descriptor to 65536. It works. But for one thread, I can't have more than 1019 file descriptors (must be the 1024 initial limit defined by the kernel)...
    Could somebody help.
    It would be great.
    Thank you.
    Gr�goire.

    Thank you for your answer.
    I have already done all the described procedures in the link you provided.
    In fact, I used this link :
    file:///home/greg/1_NetNoLedge/LinuxTuning/linux.html
    and this other one :
    file:///home/greg/1_NetNoLedge/LinuxTuning/s1-custom-kernel-modularized.html
    Still only 1024 files allowed to be opened for one process...
    In your link, it is said :
    You need to give processes the option of increasing their file descriptor limits:
    In /etc/security/limits.conf add two lines:
    * soft nofile 1024
    * hard nofile 4096
    Suggesting that it wouldn't even be necessary recompile the kernel to allow more opened file descriptors in a process... This really isn't clear for me.
    Thank you.

  • Java Thread.sleep(timeout) is influenced by changes to System time on Linux

    Java Thread.sleep(timeout) is influenced by changes to System time on Linux
    bugId : 6311057
    I encountered this problem in redhat6/ jdk 1.6

    890651 wrote:
    Java Thread.sleep(timeout) is influenced by changes to System time on Linux
    bugId : 6311057
    I encountered this problem in redhat6/ jdk 1.6At least half the time I use it, I'd want it to be, the other half I wouldn't care.
    What are you doing with it where this might be a problem?
    Changing the system clock abruptly can cause all kinds of problems with your system anyway, because various background activities etc. often depend on file dates. Wherever possible use the "skew" method to adjust your system clock, rather than just plonking in a new value, especially if you are setting the clock backwards.

  • Matching Java thread IDs to Linux PIDs

    I have a rather complex java application running, which has on the order of 30 threads. While running some tests, I discovered (using top) that one of the java child processes was spinning. I know the offending process ID, how can I match this to a java thread id which I can obtain from a thread dump? There is an "nid" field in the dump which almost, but doesn't quite, match up with a Linux process. I am using Java 1.4.1_01 for Linux. Thanks!

    Well... this sorta works, but not really. I tried you code and added a bit more. First off, there are PIDs generated which don't seem to run for very long. Here is the java output:
    OUTPUT: PID
    OUTPUT: 18530
    OUTPUT: 19389
    OUTPUT: 19400
    And here is a ps listing (truncated):
    |-bash(18530)---java(19389)---java(19390)-+-java(19391)
    |-java(19392)
    |-java(19393)
    |-java(19394)
    |-java(19395)
    |-java(19396)
    |-java(19397)
    `-java(19405)
    PID 19400 isn't even listed. Also, I spawned some more threads and these never got recognized correctly either. PIDs taken from the "ps" the moment after the threads are created do not stay around; pstree done some time later shows the threads are not running.
    Besides, how is this supposed to be used in a production system to map PIDs to TIDs? Do a "ps -Topid" every time a new Thread is created anywhere in the system? Yuck! It looks like Sun really needs to provide this support in the threaddump.
    Thanks anyway.

  • Question about java thread implementation

    Hi All,
    I am comparing the performance of the Dining philosopher's problem
    implemented in Java, Ada, C/Pthread, and the experimental language I
    have been working on.
    The algorithm is very simple: let a butler to restrict entry to the
    eating table, so that deadlock is prevented.
    It turns out that the java code is the winner and it is 2 times faster than C!
    The comparison result really surprised me, and raised a big
    question mark : why java runs so fast? I did not use high-level synchronization
    constructs like Semaphores, atomic variables, etc.
    I vaguely recall that Java thread is actually implemented by the underlying
    system thread library(so on linux, the default would be NPTL, on windows NT threads,
    and on Mac OSX it would be Cthread?). Can no longer remember where I read that.
    Does anyone here have some notions about the Java thread
    implementations(where is this formally explained)? or Does anyone know where
    I can possibly find relevant literature or the answer?
    thanks a lot.
    cheers,
    Tony

    Peter__Lawrey wrote:
    google has lots of information on java threaded.
    One thing java does is support biased locking. i.e. the thread which last locked an object can lock that object again faster.
    This may explain the difference. [http://www.google.co.uk/search?q=java+usebiasedlocking]
    Note: you can turn this option off and other locking options to see if a feature is giving you the performance advantage.
    Personally I have found that real world multi-threaded applications are easier to write in Java, esp. when you have a team of developers. For this reason, alot of C/C++ libraries are single threaded, even when there would be a performance advantage in being multi-threaded (because its just too hard in reality to make it thread safe and faster because of it)I didn't know that, very interesting :-)

  • How to assigne Java thread to a specific cpu core

    Hello everyone,
    I want to ask a complicated question. How can I assign Java threads to specific core in a multi-threaded application. The underlyinsg OS can be Linux or Windows. Is there any option provided in JVM can do it?
    If I want to fork a process using C, how can I mix the Java and C together.
    I am looking forward your suggestions.
    Thank you.

    yang2007 wrote:
    Can I fork several Java processes using C and letting each Java process run on a core? These would be questions for a C forum, or one for the OS on which you wish to run this.
    The benefit may be to reduce the interference.You're assuming that you are smarter at thread scheduling than the algorithms written, tested, and honed over decades by people whose job is specifically that.

  • Calling pl/sql api through multiple java threads

    Hi All,
    I need to call a pl/sql api from multiple java threads simultaneously and all thread will use same db connection.
    I want to know if all the threads will simultaneously call the pl/sql api then will the local variable inside pl/sql procedure be shared between them or they will get separate instances of variables.
    TIA

    You cannot make multiple parallel client calls over the same Oracle session handle. There is a single non-threaded/non-fibre serialised server process servicing client requests for that session. (physical process on Linux/Unix, thread in the oracle.exe process on Windows).
    Each thread on the client side, needs its very own Oracle session. Thus each thread will have a server process footprint on the server. Which could be problematic if 10 clients each starts 10 threads - as it means a 100 processes on the server are needed to service these client threads.
    Have a look at Overview of OCI Multithreaded Development in the Oracle® Call Interface Programmer's Guide for how to use the threading call interface of the OCI - as oppose to rolling your own where each thread manually needs to deal with is OCI session context.

  • A.out as Java Thread?

    Hello,
    I am programming in linux and I want to incorporate a C program (compiled to a.out) as a java thread.
    Is there any lazy way to do this, or would I have to:
    1. Compile it to object code,
    2. Link the object code as a shared library,
    3. Load the library in the java program and make a <code>public native int main()</code> function?
    I will also probably be running this in linux also.
    Thanks for any help!

    Well, I guess it depends on what you call the
    operating system. You could write an entire
    operating system for a virtual machine. Some things,
    like the file system, would be backed by the existing
    file systems, but what the hell? Do it anyway.
    Another project, which might be a bit more feasible
    and have more immediate benefits, would be to write
    an entire shell in Java. Let me suggest it this way:
    Write a shell in java such that you could, on a
    Windows box, start it up, then kill Explorer (not
    MSIE, I mean the Explorer shell) and use this thing
    instead, and not feel that you're hindered from doing
    anything useful.
    This might end up intersecting with the java desktop
    project. I don't know.Actually, it may be easier to use a Linux or BSD kernel, and build a shell off of that...although you would have to learn the system calls, and the GUI wouldn't be available unless you also ported the motif widget toolkit.
    If you used something like the Java-GNOME (which ports the GTK toolkit, if I remember correctly) to write the shell from scratch.
    What you would more probably do is something similiar to how mac os x works: on top of the Mach kernel, write another OS to be run by Mach. A Java OS in bytecode that mach runs, in this case. This would, however, be slow since it would be interpreted.
    It would simply be a mach kernel running the JVM which then interprets everything else. Interesting...
    The windows NT kernel is too unstable for any practical use (in my opinion), with its multithreading method.

  • Threading model: Linux, MacOSX, Win32

    Hi,
    I've been searching these forums for topics regarding Java threading models for the three operating systems for which we build Java applications: Linux, MacOSX and Windows. So far, I've only got a clear picture on the Win32 environment. It uses native threads, which I'm told is best for performance.
    My question is: what threading models do the virtual machines for Linux and MacOSX support these days? Are they working with socalled "green threads" or do they use the more powerful native threads as well? I can't seem to find any recent posts with information on this subject.
    Thanks in advance

    Here is an article that you might find interesting:
    Programming Java threads in the real world
    http://www.javaworld.com/javaworld/jw-09-1998/jw-09-threads.html
    Jesper

  • Java running under linux with crontab

    I'm having a problem:
    i want to run a java program under linux with crontab.
    my classes are in a directory and aren't in a package. i run em by invoking ./start which is a small script that i wrote. The script is in the same dir as the classes and invokes java by "java Main >>logjava.txt " but this doesn't seem to work all i get is an empty logfile
    i need to run the program every day at 0800 so i inserted the following in crontab:
    0 8 * 1-5 /var/"path"/start > logjava (where path is the path to the classes dir)
    if i run the cmdline from anywhere on the prompt i get the result i want. I think it's because the cron runs it from the root dir thus making java unable to find the classes
    Any suggestions would be welcome. or can some1 tell me how to make linux executables from the java (i usually use jsmooth for the windows exe)

    You can execute several commands in the process started by cron. You separate them using semicolons.
    Have you tried a cron entry like this:
    0 8 * 1-5 cd /var/"path";pwd;echo $PATH; ./start > logjavaOr, you may need to make sure the process started by cron gets the same environment as your interactive shells do, by explicitly loading your setup or .login scripts:
    0 8 * 1-5 . $HOME/.setup;cd /var/"path";pwd;echo $PATH; ./start > logjava

  • Java Threads not being released after loggin off

    Hello everyone,
    We are seeing a weird problem in our PI 7.0 box.
    Once I logout from the XI box (both ABAP and Java stck) my basis tem still sees Java threads aginst my id still open. Our system does not seem to be realeasing Java threads.
    Is this a know problem? What are the remidition steps.

    Hi,
    Are there existing HTTP sessions only?
    The following might be helpful.
    http://help.sap.com/saphelp_nw73/helpdata/en/c7/5ee440ba994fa3b187ff2f050cfe7c/content.htm
    http://wiki.sdn.sap.com/wiki/display/ERPHCM/Sessionnotendingafterlogoff
    Regards,
    Varun

  • Java threads monitoring

    I am using Java threads in my Java program, running on Windows Professional 2000. I am monitoring the threads using Windows Performance Monitor (WPM). However, even running a small Java program which creates only 2 threads, results in many (at least 10) instances of Java threads being reported by the WPM. Problem is, in WPM, there is no way to determine which threads in the WPM are the threads that I programmatically created. Any ideas on how to determine this?
    Thanks.
    Rhodie

    Hi Dmirty ,
    To handle large asynchronous message   in queues you can use  message packaging where multiple message are processed in one package . to make it applicable you have to perform these simple steps
    1. go to SXMB_ADM add one RUNTIME parameter PACKAGING and value 1
    2 GO TO transaction SXMS_BCONF set delay time 0 message count 100 messages and package size 1000 KB
    with these setting your improvement will increase .secondly also put  IN SXMB_ADM monitor category parameter QRFC_RESTART_ALLOWED TO 1
    this will automatically start your queue . Only thing you have to take care if you enable packaging them don't keep too many parallel queue i.e EO_INBOUND_PARALLEL and EO_OUTBOUND_PARALLEL should be less than 20
    Regards,
    Saurabh

  • Java Threads Problem

    Hi, I am trying to write a simple java threads program where in one thread reads a file and another thread writes the data into a second file....
    Here is my code, although i think i am correct, my program still runs in a sequential fashion help help help!!!
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    class MyThread extends Thread{
    private int a;
    private int c;
    FileInputStream in;
    FileOutputStream out;
    public MyThread(int a){
    this.a = a;
    public void run(){
    if(this.a==5)
         try {
         in = new FileInputStream("Britney.txt");
    } catch (FileNotFoundException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
    try {
         while((c=in.read())!=-1)
              a = (char) c;
              System.out.println(a);
    catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
    if(this.a==10)
         try {
              out = new FileOutputStream("romi.txt");
         } catch (FileNotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
         for(int i = 0;i<50;i++)
              try {
                   System.out.println(c);
                   out.write(c);
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    class MainMyThread{
    public static void main(String args[]){
    MyThread thr1, thr2;
    thr1 = new MyThread(5);
    thr2 = new MyThread(10);
    thr1.start();
    thr2.start();
    }

    Encephalopathic wrote:
    malcolmmc wrote:
    ... Chances of getting any kind of reply except "me too" can be pretty remote. ....there's actually a better chance of getting a reply on a general forum like this one, ....Can't you just post in both the narrow and the general forum, but include links one to the other in each thread? Or is that against the forum rules/etiquette? Most people here are ok with a crosspost IF those links are included.
    I would also ask that the OP designate one of those threads as the real discussion thread and just direct folks there from the other threads, so that we have one coherent discussion. If he does that, there's no problem with trying to reach out to as broad an audience as possible.
    I would figure that if the poster were upfront about what they are doing, folks wouldn't mind, but I could be wrong.I think that's generally the case. As long as the discussion is confined to one thread (and pointed there from the crossposts) or at the very least all the participants can see all the discussions, I think most people don't have a problem with it. It's when we waste our time answering when he's already got the answer elsewhere that's annoying.

  • Java thread not working in windows 7

    I have a Java app that runs just fine on Windows XP. However, on Windows 7 there is a problem related to a job being done via a Java thread.
    Background: The app spawns a separate job via a Java thread and continues on while the spawned job executes. In other words, 2 things happen at once.
    Problem: On Windows 7, when the app spawns the job, Windows sits and waits for the spawned job to complete before it continues on. In other words, 2 things DO NOT happen at once.
    It's as if Java threading does not work in Windows 7. Any input would be greatly appreciated. Thanks.

    l_sleven wrote:
    Thanks for the input, guys. From now on I'll be sure to include a SSCCE.
    I'm beginning to believe this is actually my ignorance of threading in SWT, and XP was more forgiving than 7.
    I would include a SSCCE, but of the 4 different ways I tried to get this to work I wouldn't know which to include since all failed to fix the problem.
    If you want to identify a link to a web page identifying 'best practices' for SWT threading, that would be great. Be aware though that there's a good chance I've already googled the page.
    A programmer smarter than me once said, "The road to best practices is a bumpy ride".[Concurrency in Swing|http://download.oracle.com/javase/tutorial/uiswing/concurrency/index.html]

  • Java thread with high CPU usage

    Hi,
    Running prstat -L -p pid on Solaris produces a list of lwp threads running in that process that are consuming the most CPU. Out of about 7 threads that were associated with kernel threads in pstack output, only 5 of them were mapped to a JVM thread dump. How is it possible to have a Java thread consuming CPU that doesn't show up in a thread dump?
    Thanks,
    J.S.

    And, any idea what this thread is doing?
    Here's pstack output for this missing thread 12:
    ----------------- lwp# 18 / thread# 12 --------------------
    fe0e48b4 __1cHCompileSflatten_alias_type6kMpknHTypePtr__3_ (b6001780, 100360, fe4c8000, b6001780, 100360, 0) + 4d8
    fe0f42ac __1cHCompilePget_alias_index6kMpknHTypePtr__I_ (b6001780, 100360, b6001264, 7e2bb8, 41f4, 7e2bb8) + 8
    fe11131c __1cJStoreNodeFIdeal6MpnIPhaseGVN_pnLPhaseDefUse__pnENode__ (0, 7dd5b4, 5035ec, 7e2bb8, b6001144, b6001264) + 128
    fe0c1224 __1cMPhaseIterGVNNtransform_old6MpnENode__2_ (0, b6001144, 7e2bb8, b6001264, 7e2bb8, b600116c) + 47c
    fe17349c __1cMPhaseIterGVNIoptimize6M_v_ (24, 0, a37700, b6001110, b6001100, 3442f0) + b4
    fe1943b0 __1cOPhaseIdealLoop2t6MrnMPhaseIterGVN_pk0_v_ (b6000ee8, a3772c, 1, 4ff37c, 2000, 269568) + 7cc
    fe1cc89c __1cHCompileIOptimize6M_v_ (b6001780, b60015b8, b6001780, b60015dc, 0, b60013dc) + a0
    fe1cb69c __1cHCompile2t6MpnFciEnv_pnHciScope_pnIciMethod_ill_v_ (91f504, b6001800, db8a24, fe5296b4, b60018a0, b60018b0) + 7bc
    fe1c73f8 __1cKC2CompilerOcompile_method6MpnFciEnv_pnHciScope_pnIciMethod_il_v_ (27b18, b6001af8, db8a24, db8938, ffffffff, 1) + 70
    fe1c79fc __1cNCompileBrokerZinvoke_compiler_on_method6FpnLCompileTask__v_ (db8938, db8a24, fe4eacec, 0, 0, 8d9) + 40c
    fe280964 __1cNCompileBrokerUcompiler_thread_loop6F_v_ (28758, 13a570, fe4c8000, b6001d10, fe4c8000, ffffffff) + 168
    fe216200 __1cKJavaThreadDrun6M_v_ (b5e02000, fe4d3e34, fe4c8000, 1ffd70, 13a570, 1ffd70) + 3d8
    fe213ec8 _start   (fe4c8000, ff325d10, 0, 5, 1, fe401000) + 20
    ff36b734 threadstart (13a570, 0, 0, 0, 0, 0) + 40

Maybe you are looking for