[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

thread creation

Posted on 2014-02-04
6
Medium Priority
?
366 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 19

Accepted Solution

by:
Ken Butters earned 1600 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 400 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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 will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

650 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