creating multiple threads

creating multiple threads

View Answers

April 2, 2009 at 6:02 PM

Hi friend,

Use the following code:

import java.util.*;

class MyThread extends Thread{
MyThread(String s){
super(s);
start();
}
public void run(){
for(int i=0;i<5;i++){
System.out.println("Thread Name :"
+Thread.currentThread().getName());
try{
Stack stac = new Stack();
Thread.sleep(1000);
System.out.print ("Push ");
for (int j = 1; j <= 5; j++)
{
System.out.print (stac.push(new Integer(j) ));
}
System.out.print ( "Pop " );
while ( !stac.empty() )
{
System.out.print ( stac.pop() );
}
}catch(Exception e){}
}
}
}
public class CreateStack{
public static void main(String args[]){
System.out.println("Thread Name :"+Thread.currentThread().getName());
MyThread m1=new MyThread("My Thread 1");
MyThread m2=new MyThread("My Thread 2");
}
}
Thanks









Related Tutorials/Questions & Answers:
creating multiple threads - Java Beginners
creating multiple threads  demonstrate a java program using multiple thread to create stack and perform both push and pop operation synchronously.  Hi friend, Use the following code: import java.util.*; class
Creating multiple Threads
to override run() method.Example : Code for creating multiple thread. public...In this section you will learn how to create multiple thread in java. Thread... multiple thread to run concurrently. Each and every thread has the priority
Advertisements
Execution of Multiple Threads in Java
Execution of Multiple Threads in Java  Can anyone tell me how multiple threads get executed in java??I mean to say that after having called the start method,the run is also invoked, right??Now in my main method if I want
Creating Multiple ArrayList
Creating Multiple ArrayList   I want to create multiple ArrayList . import java.util.*; class ArrayListNames{ public static void main(String args[]){ //here i want to create 10 arraylists of type string
threads
threads  what are threads? what is the use in progarmming
Creating Multiple Type List
Creating Multiple Type List       This example is shows how to create the list which has multiple... Suman: not selected     The MULTIPLE keyword is used
threads in java
threads in java  how to read a file in java , split it and write into two different files using threads such that thread is running twice
threads and events
threads and events  Can you explain threads and events in java for me. Thank you.   Java Event Handling Java Thread Examples
Java threads
Java threads  What are the two basic ways in which classes that can be run as threads may be defined
disadvantage of threads
is the disadvantage of threads?   hello,ADS_TO_REPLACE_1 The Main disadvantage of in threads these are operating system dependent.   Hi, Here... the disadvantages of threads. The global variables defined in the application is not thread
Sync Threads
Sync Threads  "If two threads wants to execute a synchronized method in a class, and both threads are using the same instance of the class to invoke the method then only one thread can execute the method at a time." This is what
Explain about threads:how to start program in threads?
Explain about threads:how to start program in threads?  import...; Learn Threads   Thread is a path of execution of a program... more than one thread. Every program has at least one thread. Threads are used
threads in java
threads in java  iam getting that the local variable is never read in eclipse in main classas:: class Synex4{ public static void main(String args[]){ Test1 ob1=new Test1(); //local variable never read
Reading and writting multiple files
Reading and writting multiple files  how can i read and write say two different files at the same time using threads
Creation of Multiple Threads
Creation of Multiple Threads   ... In this program, two threads are created along with the "main"... for 1000 milliseconds(1 second) and switches to the another threads to execute
Synchronized Threads
? to prevent data from being corrupted by multiple threads by a keyword synchronized... has both synchronized and non-synchronized methods, multiple threads can... Synchronized Threads      
threads
threads
Threads
Threads
Threads
Threads
Version of cornerstone-threads>cornerstone-threads-tutorial dependency
List of Version of cornerstone-threads>cornerstone-threads-tutorial dependency
Version of cornerstone-threads>cornerstone-threads-api dependency
List of Version of cornerstone-threads>cornerstone-threads-api dependency
Version of cornerstone-threads>cornerstone-threads-impl dependency
List of Version of cornerstone-threads>cornerstone-threads-impl dependency
Running threads in servlet only once - JSP-Servlet
Running threads in servlet only once  Hi All, I am developing a project with multiple threads which will run to check database continuously. With those two separate threads I can check with database and do some other
Synchronized Threads
? to prevent data from being corrupted by multiple threads by a keyword synchronized... Synchronized Threads       In Java, the threads are executed independently to each other. These types
Synchronized Threads
? to prevent data from being corrupted by multiple threads by a keyword synchronized... has both synchronized and non-synchronized methods, multiple threads can... Synchronized Threads      
Threads in realtime projects
Threads in realtime projects  Explain where we use threads in realtime projects with example
ModuleNotFoundError: No module named 'threads'
ModuleNotFoundError: No module named 'threads'  Hi, My Python... 'threads' How to remove the ModuleNotFoundError: No module named 'threads... to install padas library. You can install threads python with following command
Coding for life cycle in threads
Coding for life cycle in threads  program for life cycle in threads
multiple inhertence
multiple inhertence  package start; class A { protected void a() //a method in A { System.out.println... { public static void main(String arg[]) { //Creating
multiple inhertence
multiple inhertence  package start; class A { protected void a() //a method in A { System.out.println... { public static void main(String arg[]) { //Creating
Version of cornerstone-threads-tutorial>cornerstone-threads-tutorial dependency
List of Version of cornerstone-threads-tutorial>cornerstone-threads-tutorial dependency
Version of cornerstone-threads-api>cornerstone-threads-api dependency
List of Version of cornerstone-threads-api>cornerstone-threads-api dependency
Version of cornerstone-threads-impl>cornerstone-threads-impl dependency
List of Version of cornerstone-threads-impl>cornerstone-threads-impl dependency
interfaces,exceptions,threads
with multiple threads is referred to as a multi-threaded process. In Java Programming... THE COMPLETE CONEPTS OF INTERFACES,EXCEPTIONS,THREADS   Interface... class. In java, multiple inheritance is achieved by using the interface
multiple inheritance.
multiple inheritance.  hello, can java support multiple inheritance???   hi,ADS_TO_REPLACE_1 java does not support multiple inheritance
Examples on threads and mulithreading.....
Examples on threads and mulithreading.....  Is any good examples on threads and Mulithreading...   Hi Friend, Please visit the following link:ADS_TO_REPLACE_1 Thread Tutorial Thanks
Java - Threads in Java
or multiprogramming is delivered through the running of multiple threads concurrently... Java - Threads in Java       Thread is the feature of mostly languages including Java. Threads
Threads - Java Interview Questions
Threads  creating a thread is two ways?extends with thread class and implements runnabule interface. What is the diffrence between those two?which.... If you want to create threads, please visit the following link: http
java threads - Java Beginners
java threads  What are the two basic ways in which classes that can be run as threads may be defined
Creating Multiple Lists
Creating Multiple Lists In this program we are going to tell you how you can make lists into a pdf files. You can make lists and also make  sublist You can make ordered list or symbolic list. iText
Artifacts of cornerstone-threads
List of Artifacts of cornerstone-threads maven depenency
Artifacts of cornerstone-threads-api
List of Artifacts of cornerstone-threads-api maven depenency
Artifacts of cornerstone-threads-impl
List of Artifacts of cornerstone-threads-impl maven depenency
Artifacts of cornerstone-threads-tutorial
List of Artifacts of cornerstone-threads-tutorial maven depenency
multiple inheritance
multiple inheritance  Class A extends Class B but Class A also inherit Super Class Object so it is multiple inheritence give reason in support of your answer
multiple inheritance
multiple inheritance  why java doesn't support multiple inheritance? we can achieve this by using interface but not with classes? what is the main reason that java community implemented like
Creating an Applet
Creating an Applet  Hi, I have get a task regarding Creating an Applet using all Layout Manager, can anyone help me in this regard. I donā??t know how to make and please help me. Thanks.   To answer of your query

Ads