How many  threads are running?

here's the code... i am trying to understand, at each point, how many threads are running:
I understand that one thread belongs to the caller of the start()
& at the same time there is another thread belonging to the instances of each thread (thread1, thread2, thread 3 etc.)
1public class ThreadTester {
2   public static void main( String args[] )
3   {
4      PrintThread thread1, thread2, thread3, thread4;
5
6      thread1 = new PrintThread( "thread1" );
7      thread2 = new PrintThread( "thread2" );
8      thread3 = new PrintThread( "thread3" );
9      thread4 = new PrintThread( "thread4" );
10
11      System.err.println( "\nStarting threads" );
12
13      thread1.start();
14      thread2.start();
15      thread3.start();
16      thread4.start();
17
18      System.err.println( "Threads started\n" );
19   }
}can you tell me if i am counting the number of threads in existance correctly...
LINE#.....CALLER...START...TOTAL THREADS
13..............1.........1.......2
14..............1+1......1+1.....4
15..............2+1......2+1.....6
16..............3+1......3+1.....8
so by the time line 16 executes i have a total of 8 threads,
4 threads belonging to each caller plus
4 threads created by start()
or is it
LINE#.....CALLER...START...TOTAL THREADS
13..............1........1........2
14..............1........1+1.....3
15..............1........2+1.....4
16..............1........3+1.....5
after line 16 executes does the caller thread die, thus leaving only a total of 4 threads?
there is only one thread belonging to the caller at line 13(plus the thread it creates).
at the start of line 14, the previous callers thread is dead & now a new thread is created that belongs to the caller on line 14... etc.

well, i realize at the end there would be 4 threads but im trying to get my head around this explanation in the book:
"A program launches a threads executioin by calling the threads start method, which in turn call the run method. After start launches the thread, start returns to tis caller immediately. The caller then executes concurrently with the lauched thread." there fore if i have 2 concurrent processes, are there 2 threads running????
now having said the above, my question was:
for each line,
how many threads are in existance at
line13
line14
line15
line16
thanks.

Similar Messages

  • How many instance are running ?

    Dear Friends ,
    how do i figure out how many instance are running on database? OR , How many database are running in a server ? Is it possible to find out from 'os' or 'database' level ?
    Waiting for ur kind reply ... ...
    Edited by: shipon_97 on Sep 4, 2008 10:38 AM

    Hi,
    On unix/linux use: ps -fea|grep pmon
    This will show all pmon process running (Each one is an Instance and you will see the name of the Instance here too), you can also check on /etc/oratab all the oracle databases in the server.
    On Windows go to Control Panel, Administration, Services and take a look on the Oracle services.
    Cheers,
    Francisco Munoz Alvarez
    www.oraclenz.com

  • How to detect how many JFrames are running

    Hi,
    how can I detect how many JFrames are open? I would like to call System.exit(0) only when no other windows (apart from the current one) is running.
    Thanks

    There is no way they would close. You need to create another child of the main class, and by doing that, you can have as many frames as you like. And like the other guy said, you need to have a counter that increases or decreases as you open and close your frames.
    if you still have problems doing it, send me your code and I will help you out.
    [email protected]
    Phife

  • At how many FPS are running my games?

    Well, i'm playing, for example, on a game like Warcraft III, and I want to know at how many FPS it runs.
    How can I get this information?
    Greetings

    Depends upon the game, but in Warcraft III (and many other games) simply enter '/fps' in the chat box and the information should show on screen

  • How many FNDLIBR are running?

    Hi:
    What does this command mean: ps -ef|grep FNDLIBR|wc -c ? I got 3339 returns. Thank you!
    11.5.10.2
    unix

    HI,
    This command will retrurn the total number of characters found the ps -ef|grep FNDLIBR.
    But it is of no use. You can use the following to know how many concurrent managers are running.
    $ps -ef|grep FNDLIBR|grep -v grep |wc -l
    Thanks

  • How many threads are used to load an webpage in webview?

    I implemented a custom version of cookiemanage to overcome the problem of cookies being stored retrived in the same place for webview (when assigning a custom cookiemanager to default cookiehandler before initializing webview ).
    This custom class uses thread local to create a new store for each thread, so i could have varius webview instance not using the same cookiestore.Well, it doesn´t work because
    webview apperantly creates about 20 threads for loading (login) a webpage.I´m guessing webview uses several threads to load an webpage, because in my custom implementation of cookiemanager each thread that request
    CookieHandler.getdefault() get a new cookie store, i did this with threadlocal.
    My question to the experts is ::
    - Is my teory correct and weview creats several threads to load a page or i´m missing something where?
    - Also having my problem is there an way i can restrict webview so it only creates one thread or at least only one thread that call cookiemanager.getDefault()?
    Even not knowing the answers to the above , any details on webview inside working relating thread could be helpfull.
    Many Thanks
    André

    To print all Threads;
    class Equitus {
        public static void main(String[] arg) {
            new Equitus().run();
        public void run() {
            ThreadGroup tg = Thread.currentThread().getThreadGroup();
            for(ThreadGroup parent; (parent=tg.getParent()) != null; tg=parent) ;
            Thread[] threads;
            do {
                threads = new Thread[tg.activeCount()];
            } while (tg.enumerate(threads)!=threads.length);
            System.out.println(java.util.Arrays.toString(threads));
    }

  • How many JVM are there in a computer?

    For exemple, I open two dos windows in WIN98, and type "java x" "java y " seperately in the two dos windows. How many JVM are running in my computer?
    Thanks!

    Good day,
    As far as I can tell, I would say that only one client JVM can be active at anypoint of time, however since Java is a multi-threads program, you will end up with more active threads in your system while the applications will be running, somehow similar to a Windows application, such as Word when you have more than one opened document at once.
    To have a better evaluation of the system requirements and usage, such as the memory, handles, threads, active processes etc, I would strongly suggest you do to a search for TaskInfo 2003. I've been evaluating that program for the last few days and I'm amazed by the different pieces of information that program can provide.
    By the way, I'm not affilited to the TaskInfo developper in any way shape or form, I just mentioned it based on my current evaluation.
    Hope that helps.

  • How many databases can run in a server

    How many databases can run in a server, how can we find how many databases are running there – in OS level for UNIX

    You can have as many oracle instances as your system resources and kernel parameters allow you to.
    A quick search to know how many oracle instances are running, check the OS processes:
    ps -ef | grep smon
    This will list all smon manadatory instance processes, this way you'll know how many concurrently instances are running.
    ~ Madrid.

  • How Many Threads inside JVm while running

    Hi,
    how many threads will be there in jvm of 1.4 or higher sdk? threads i mean it includes all jvm threads also.

    How do you identify these threads?
    I can see 8 threads in my 1.5 java process (just running a main) using windows XP task manager, but when I check how many threads there are from within the code, it only looks like 4:
    java.lang.ThreadGroup[name=system,maxpri=10]
    Thread[Reference Handler,10,system]
    Thread[Finalizer,8,system]
    Thread[Signal Dispatcher,9,system]
    java.lang.ThreadGroup[name=main,maxpri=10]
    Thread[main,5,main]
    For example, using
    Thread.currentThread().getThreadGroup().getParent().list();

  • How many threads can be running at the same time

    Hi!!
    Dows anyone knows how many Threads can be running at the same time in the JVM.
    I'm making a multi thread client-server app and I would like to know how much simultneous connections the JVM support. I'm using one Thread per connection.

    Hi, thanks to all for your answers.
    I think that I made the wrong question, as you said: "that means the number of threads currently created".
    I'm worry about this because my application is already online (It's a mail server -SMTP and POP3 server using ORACLE for the users database- ) and some other user post in the "multi-tread forum" that almost any JVM can only have 700 threads created at the same time, and I've never heard or read anything about this.
    what you mean with the stack space (memory??)
    I'm using the JavaWebServer 2.0 and a servlet to start the main Thread.
    Again Thanks to all for the answers but I think that the schapel answer is the one that solve my doubt...

  • How many activities are correctally running on my schcema

    Hi,
    1)how can i find out , how many queies are correctally running on my schcema with same identity or with out ?
    2)how many activities are correctally running on my schcema ?
    yorus sincerely

    Sorry, I've read your post a number of times and I can't understand either question.
    Can you rephrase or clarify?
    Just guessing, but you might start by looking at v$sql and v$session.
    You should also post your Oracle version number. Not 10g or 11g but the exact number (do a select * from v$version).

  • Having issues finding out how many bytes are sent/recieved from a socket.

    Hello everyone.
    I've searched the forums and also google and it seems I can't find a way to figure out how many bytes are sent from a socket and then how many bytes are read in from a socket.
    My server program accepts a string (an event) and I parse that string up, gathering the relevant information and I need to send it to another server for more processing.
    Inside my server program after receiving the data ( a string) I then open another port and send it off to the other server. But I would like to know how many bytes I send from my server to the other server via the client socket.
    So at the end of the connection I can compare the lengths to make sure, I sent as many bytes as the server on the other end received.
    Here's my run() function in my server program (my server is multi threaded, so on each new client connection it spawns a new thread and does the following):
    NOTE: this line is where it sends the string to the other server:
    //sending the string version of the message object to the
                        //output server
                        out.println(msg.toString());
    //SERVER
    public class MultiThreadServer implements Runnable {
         Socket csocket;
         MultiThreadServer(Socket csocket) {
              this.csocket = csocket;
         public void run() {
              //setting up sockets
              Socket outputServ = null;
              //create a message database to store events
              MessageDB testDB = new MessageDB();
              try {
                   //setting up channel to recieve events from the omnibus server
                   BufferedReader in = new BufferedReader(new InputStreamReader(
                             csocket.getInputStream()));
                   //This socket will be used to send events to the z/OS reciever
                   //we will need a new socket each time because this is a multi-threaded
                   //server thus, the  z/OS reciever (outputServ) will need to be
                   //multi threaded to handle all the output.
                   outputServ = new Socket("localhost", 1234);
                   //Setting up channel to send data to outputserv
                   PrintWriter out = new PrintWriter(new OutputStreamWriter(outputServ
                             .getOutputStream()));
                   String input;
                   //accepting events from omnibus server and storing them
                   //in a string for later processing.
                   while ((input = in.readLine()) != null) {
                        //accepting and printing out events from omnibus server
                        //also printing out connected client information
                        System.out.println("Event from: "
                                  + csocket.getInetAddress().getHostName() + "-> "
                                  + input + "\n");
                        System.out.println("Waiting for data...");
                        //---------putting string into a message object-------------///
                        // creating a scanner to parse
                        Scanner scanner = new Scanner(input);
                        Scanner scannerPop = new Scanner(input);
                        //Creating a new message to hold information
                        Message msg = new Message();                    
                        //place Scanner object here:
                        MessageParser.printTokens(scanner);
                        MessageParser.populateMessage(scannerPop, msg, input);
                        //calculating the length of the message once its populated with data
                        int length = msg.toString().length();
                        msg.SizeOfPacket = length;
                        //Printing test message
                        System.out.println("-------PRINTING MESSAGE BEFORE INSERT IN DB------\n");
                        System.out.println(msg.toString());
                        System.out.println("----------END PRINT----------\n");
                        //adding message to database
                        testDB.add(msg);
                        System.out.println("-------Accessing data from Map----\n");
                        testDB.print();
                        //---------------End of putting string into a message object----//
                        //sending the string version of the message object to the
                        //output server
                        out.println(msg.toString());
                        System.out.println("Waiting for data...");
                        out.flush();
                   //cleaning up
                   System.out.println("Connection closed by client.");
                   in.close();
                   out.close();
                   outputServ.close();
                   csocket.close();
              catch (SocketException e) {
                   System.err.println("Socket error: " + e);
              catch (UnknownHostException e) {
                   System.out.println("Unknown host: " + e);
              } catch (IOException e) {
                   System.out.println("IOException: " + e);
    }Heres the other server that is accepting the string:
    public class MultiThreadServer implements Runnable {
         Socket csocket;
         MultiThreadServer(Socket csocket) {
              this.csocket = csocket;
         public void run() {
              try {
                   //setting up channel to recieve events from the parser server
                   BufferedReader in = new BufferedReader(new InputStreamReader(
                             csocket.getInputStream()));
                   String input;
                   while ((input = in.readLine()) != null) {
                        //accepting and printing out events from omnibus server
                        //also printing out connected client information
                        System.out.println("Event from: "
                                  + csocket.getInetAddress().getHostName() + "-> "
                                  + input + "\n");
    System.out.println("Lenght of the string was: " + input.length());
                        System.out.println("Waiting for data...");
                   //cleaning up
                   System.out.println("Connection closed by client.");
                   in.close();
                   csocket.close();
              } catch (IOException e) {
                   System.out.println(e);
                   e.printStackTrace();
    }Here's an example of the program works right now:
    Someone sends me a string such as this:
    Enter port to run server on:
    5656
    Listening on : ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=5656]
    Waiting for client connection...
    Socket[addr=/127.0.0.1,port=4919,localport=5656] connected.
    hostname: localhost
    Ip address: 127.0.0.1:5656
    Waiting for data...
    Event from: localhost-> UPDATE: "@busch2.raleigh.ibm.com->NmosPingFail1",424,"9.27.132.139","","Omnibus","Precision Monitor Probe","Precision Monitor","@busch2.raleigh.ibm.com->NmosPingFail",5,"Ping fail for 9.27.132.139: ICMP reply timed out",07/05/07 12:29:12,07/03/07 18:02:31,07/05/07 12:29:09,07/05/07 12:29:09,0,1,194,8000,0,"",65534,0,0,0,"NmosPingFail",0,0,0,"","",0,0,"",0,"0",120,1,"9.27.132.139","","","","dyn9027132107.raleigh.ibm.com","","","",0,0,"","","NCOMS",424,""
    Now my program makes it all nice and filters out the junk and resends the new string to the other server running here:
    Enter port to run server on:
    1234
    Listening on : ServerSocket[addr=0.0.0.0/0.0.0.0,port=0,localport=1234]
    Waiting for client connection...
    Socket[addr=/127.0.0.1,port=4920,localport=1234] connected.
    Parser client connected.
    hostname: localhost
    Ip address: 127.0.0.1:1234
    Event from: localhost-> PacketType: UPDATE , SizeOfPacket: 577 , PacketID: 1, Identifer: UPDATE: "@busch2.raleigh.ibm.com->NmosPingFail1" , Serial: 424 , Node: "9.27.132.139" , NodeAlias: "" , Manager: "Omnibus" , Agent: "Precision Monitor Probe" , AlertGroup: "Precision Monitor" , AlertKey: "@busch2.raleigh.ibm.com->NmosPingFail" , Severity: 5 , Summary: "Ping fail for 9.27.132.139: ICMP reply timed out",StateChange: 07/05/07 12:29:12 , FirstOccurance: 07/03/07 18:02:31 , LastOccurance: 07/05/07 12:29:09 , InternalLast: 07/05/07 12:29:09 , EventId: "NmosPingFail" , LocalNodeAlias: "9.27.132.139"
    Lenght of the string was: 579
    The length of the final string I sent is 577 by using the string.length() function, but when I re-read the length after the send 2 more bytes got added, and now the length is 579.
    I tested it for several cases and in all cases its adding 2 extra bytes.
    Anyways, I think this is a bad solution to my problem but is the only one I could think of.
    Any help would be great!

    (a) You are counting characters, not bytes, and you aren't counting the line terminators that are appended by println() and removed by readLine().
    (b) You don't need to do any of this. TCP doesn't lose data. If the receiver manages get as far as reading the line terminator when reading a line, the line will be complete. Otherwise it will get an exception.
    (c) You are assuming that the original input and the result of message.toString() after constructing a Message from 'input' are the same but there is no evidence to this effect in the code you've posted. Clearly this assumption is what is at fault.
    (d) If you really want to count bytes, write yourself a FilterInputStream and a FilterOutputStream and wrap them around the socket streams before decorating them with the readers you are using. Have these classes count the bytes going past.
    (e) Don't use PrintWriter or PrintStream on socket streams unless you like exceptions being ignored. Judging by your desire to count characters, you shouldn't like this at all. Use BufferedWriter's methods to write strings and line terminators.

  • Report to show me how many invoices are being processed by users

    Hi, 
    I am currently working as a Accounts Payable Supervisor and I would like to run a report to show me how many invoices are being processed by users in my team. 
    Currently I am using Transaction F.98  (Posted Docs by user report), but this report includes posting from intercompany so all users will have duplicate invoices showing on this report. 
    Is there any other report I could run to get the result I am after?
    Many thanks
    Alex

    Hello Alex,
    You can also use the GL line item report (FBL3N) with the offsetting accounts (for example GR/IR A/c) which would be posted while posting the invoice. You can display the results with User Name and also can create a layout of your own which can be used time and again.
    Kind Regards // Shaubhik
    Edited by: Shaubhikg on Nov 10, 2010 6:02 AM

  • How to see how many users are working on a Dynpro application?

    Hello,
    Is it possible to see somwhere at the portal or on the WAS how many users are currently working with my Web Dynpro application?

    Hi Roy,
    I know it isn' exactly what you want but if you got to:-
    System Administration->Support->Web Dynpro Test Tools->User Management
    you can at least see the users currently running Web Dynpro applications (I think!)
    At least its a start!
    Cheers,
    Gareth.

  • Can I use my airport to see how many devices are on my network?

    Can I use my airport to see how many devices are on my network?

    No, that info was removed from the airport utility at v6 toyland edition.
    The last real utility was 5.6.1 and although it is not actually supposed to work on AC model it does sometimes.
    But you can generally see what is on your network using the netstat command in the computer..
    Open the network utility and go to the netstat page and run scan.. this can take a few minutes.. and should show all the clients as well as the router/s. At least all the ones the computer can see.
    The network utility is under utilized as people seem to not know of it.
    There are iOS tools like this as well. Sorry but I don't remember the name/s.

Maybe you are looking for

  • Calling a web-service from extended controller

    Hello, We are tying to consume a web-service in extended controller of a page. We created stub files using */oracle/d01/oracle/VIS/db/tech_st/11.1.0/jlib/axis.jar* and related jar files found on the E-BS Server. We are using our stub classes in the e

  • In iMovie, I can't see my iPhoto videos in the event library. Why ? this is after updating to 10.7.4

    in iMovie, I can't see my iPhoto videos in the event library. Why ? this is after updating to 10.7.4 also, if I want to use a picture in my movie, it says 'Open iPhoto to see photos from your iPhoto Library in this list.' It never use to do this.

  • Report On Cash flow

    hello experts my client requirement is a  cash flow on daily basis . selecton criteria date and gl code and the out put is Opeing bal (clubbed) and the doc number that were posted against that gl If possble plz attach a code thank you

  • Dreamweaver Tag Issues

    On editing PHP files i have created on Dreamweaver, non of them seem to display on the design view. When in the code view, my opening DIV tages for my container etc change from RED to GREY to BLUE when i click on them in no particular order, as if dr

  • Utility for compiling java files with options.

    i want to create a utility application in java which can compile a java source file with options like -d , -classpath,-help etc. there is a java.lang.Compiler class which can be used to compile a source file but how can i supply compile time options?