Solved

thread creation

Posted on 2014-02-04
6
312 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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

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…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now