Answers for "multithreading in java"

2

system.in example in java

package com.mkyong.io;

import java.util.Scanner;

public class JavaScanner {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        String input = "";
        while (!"q".equalsIgnoreCase(input)) {

            System.out.print("Enter something (q to quite): ");

            input = scanner.nextLine();
            System.out.println("input : " + input);
        }

        System.out.println("bye bye!");
    }

}
Posted by: Guest on April-25-2020
18

multithreading

//Bless anyone who decides to follow this path
Posted by: Guest on February-18-2020
1

what is multithreading

Multithreading is a model of program execution 
that allows for multiple threads to be created 
within a process, executing independently but 
concurrently sharing process resources. 
Depending on the hardware, threads can run 
fully parallel if they are distributed to their own CPU core.
Posted by: Guest on August-06-2021
4

how to do multithreading

import threading

def func1():
	# your function
def func2():
	# your function
if __name__ == '__main__':
	threading.Thread(target=func1).start()
	threading.Thread(target=func2).start()
Posted by: Guest on July-30-2021
1

multithreading

#!/usr/bin/python

import thread
import time

# Define a function for the thread
def print_time( threadName, delay):
   count = 0
   while count < 5:
      time.sleep(delay)
      count += 1
      print "%s: %s" % ( threadName, time.ctime(time.time()) )

# Create two threads as follows
try:
   thread.start_new_thread( print_time, ("Thread-1", 2, ) )
   thread.start_new_thread( print_time, ("Thread-2", 4, ) )
except:
   print "Error: unable to start thread"

while 1:
   pass
Posted by: Guest on July-15-2020
2

multithreading in java

class Count implements Runnable
{
   Thread mythread ;
   Count()
   { 
      mythread = new Thread(this, "my runnable thread");
      System.out.println("my thread created" + mythread);
      mythread.start();
   }
   public void run()
   {
      try
      {
        for (int i=0 ;i<10;i++)
        {
          System.out.println("Printing the count " + i);
          Thread.sleep(1000);
        }
     }
     catch(InterruptedException e)
     {
        System.out.println("my thread interrupted");
     }
     System.out.println("mythread run is over" );
   }
}
class RunnableExample
{
    public static void main(String args[])
    {
       Count cnt = new Count();
       try
       {
          while(cnt.mythread.isAlive())
          {
            System.out.println("Main thread will be alive till the child thread is live"); 
            Thread.sleep(1500);
          }
       }
       catch(InterruptedException e)
       {
          System.out.println("Main thread interrupted");
       }
       System.out.println("Main thread run is over" );
    }
}
Posted by: Guest on November-07-2020

Code answers related to "multithreading in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language