Solved

thread creation

Posted on 2014-02-04
6
317 Views
Last Modified: 2014-02-11
Hi,

I tried below example.

http://www.avajava.com/tutorials/lessons/how-do-i-create-a-thread-in-java.html

When i run the example I  see output in irregular order.

Method 1: extending java.lang.Thread
Method 2: implementing java.lang.Runnable
ThreadSubclass is running
RunnableJob is running

How to fix this issue.

please advise
Any links resources ideas highly appreciated. Thanks in advance
0
Comment
Question by:gudii9
  • 3
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
Ken Butters earned 400 total points
ID: 39834091
What do you mean by irregular order?

Note:  when you start the two threads... there is no guarantee which thread's output will reach the console first.  They should be independent of one another.
0
 
LVL 21

Assisted Solution

by:Amitkumar Panchal
Amitkumar Panchal earned 100 total points
ID: 39837854
Well, I guess the order of last three lines in the output will not be fixed. If you are considering it as an irregular order then it is an expected behaviour in multithreading program.

The reason behind is thread scheduling and it is driven by OS. OS decides which thread to run and put it back to runnable based on no of threads in the memory and its priority.
0
 
LVL 7

Author Comment

by:gudii9
ID: 39843291
The reason behind is thread scheduling and it is driven by OS. OS decides which thread to run and put it back to runnable based on no of threads in the memory and its priority.

Which memory?
OS memory or java memory or laptop hard drive memory. please advise
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 19

Expert Comment

by:Ken Butters
ID: 39843686
Which memory?
OS memory or java memory or laptop hard drive memory. please advise

the handling of threads is done by the JVM. (Java Virtual Machine).

The JVM implementation can be different on different machines.

So the memory will be whatever memory is allocated to the JVM to run the java application.
0
 
LVL 7

Author Comment

by:gudii9
ID: 39851196
So the memory will be whatever memory is allocated to the JVM to run the java application.

How and who allocate memory to JVM. I never remember allocating memory to JVM on my windows laptop. What is the maximum memory i can allocate to JVM.


I see my windowns 7, 64 bit laptop has installed memory(RAM) of 8 GB. How and where to assign memory to jvm. By default how much memory is allocated to JVM. Please advise
0
 
LVL 19

Expert Comment

by:Ken Butters
ID: 39851256
Is your question about creating threads and the order that output from threads appear... or is it how to set JVM arguments?

Have you had your question answered about threads?

Sounds like you are moving on to another question about JVM parameters.

If your question has not been answered to your satisfaction, then you should ask for a clarification on the answer.

If your original question has been answered, you should allocate the points to the volunteer who was spent time answering your original question fully.  

Please feel free to open additional questions on additional topics as needed.

The order of the output from threads has absolutely NO impact due to the amount of memory allocated to the JVM.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
eclipse java  build path 6 56
web services creation SOAP vs REST 5 40
couple of eclipse 5 36
pagenation logic how it is working in my code 1 29
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question