Java Threading and multithreaded tutorials

Source: Internet
Author: User
Tags thread class

This article consists ofimportnew - liken translated from Journaldev. Java threads are lightweight processes that perform certain tasks. Java provides multithreaded support through the thread class, and applications can create multiple threads that execute concurrently. There are two types of threads in the application-the user thread and the daemon thread. When the app is started, the main thread is the first user thread created, and we can create multiple user threads and daemons. The JVM terminates the program when all user processes have finished executing. Different properties can be set on different threads, but there is no guarantee that high-priority threads will execute before the low-priority thread. Thread Scheduler is a partial implementation of the operating system, when a thread is started, its execution is controlled by the thread scheduler, and the JVM does not control its execution. Threads can be created by extending the Runnable interface implemented by the thread class.
12345 Thread t = newThread(new Runnable(){    @Override    public voidrun() {    }});

The above creates a new thread with a few lines of code, where the Runnable interface created as an anonymous class reads this article to learn about inner classes, nested classes, and anonymous inner classes. A few weeks ago, I've published several useful articles for threads, and you can learn threads in Java in the following order, step-by-step.

  1. Java Threading Instances

    This is the first article in the Thread tutorial series, read it to learn about processes and threads. What is the difference between threads and processes, the advantage of using threads and how to create threads using the Runnable interface and the thread class. This paper also compares the Runnable interface and the thread class.

  2. Java thread hibernation (thread sleep)

    Java thread hibernation is used to pause the currently executing thread, and in future articles we will use thread hibernation extensively, so it's best to understand how it works and how accurate it is?

  3. Java thread join (thread join)

    Sometimes we need to wait for the other threads to finish before we can continue, and we could use the join of the thread to do it, this article will learn how to join the thread and when to use it.

  4. Java Thread State (thread states)

    Understanding the different states of a thread is important, and this article will learn how the thread changes his state and how the thread scheduler changes the state of the thread.

  5. Java threads for Wait, notify, and Notifyall

    The Java object class contains three methods, using these three methods, the thread can communicate the lock state for a resource and learn how to use these methods by simply waiter-notifier the implementation.

  6. Java thread safe for synchronization (thread Safety and synchronization)

    We know that threads share object resources, but this leads to data corruption because they are not atomic operations. This article will learn to use different methods to implement Java thread safety, learn to use synchronization operators correctly, synchronized methods and synchronized blocks. This article also has a lot to do with synchronized instances and explain the problems that are associated with using them.

  7. Java exceptions in the main thread (Java Exception in thread main)

    The JVM uses the main method to create the first thread, this article describes common exceptions that are encountered daily and the root causes of these exceptions and how to resolve them.

  8. Thread safety in a singleton class (thread Safety in Singleton Class)

    This article will learn the basic concepts of creating singleton classes and what are thread safety issues and how they can be done in a singleton class of thread safety.

  9. Java daemon thread (Daemon thread)

    This article explains the daemon and how to create a daemon thread in Java.

  10. Java thread native variable (thread local)

    We know the variables of the thread-sharing object, but how do we get the thread local variables at the class level? Java provides the ThreadLocal utility class to create thread-local variables, which in this article learn how to create ThreadLocal variables in a Java program.

  11. Java thread dump (thread dump)

    The current thread information for the Java thread dump provider, which is useful for analyzing performance issues in an application or finding a solution to deadlock situations, which illustrates the different ways in which Java is used to generate thread dumps.

  12. How do I parse and avoid deadlocks in Java (what to Analyze Deadlock and avoid it in Java)

    Deadlocks are situations in which multithreading waits for a circular dependency caused by each other releasing resources. This article discusses how to create deadlocks in Java programs, how to use thread dumps to analyze deadlocks, and best practices for avoiding the deadlock of Java programs.

  13. Java Timer thread (timer thread)

    This article explains how to use the Java Timer and TimerTask classes to create tasks that run at regular intervals. Use an example to show how to use and cancel timers.

  14. Java Producer and consumer issues (Producer Consumer problem)

    Prior to Java 5, producer-consumer issues could be addressed using the Wait () and notify () methods, but the introduction of Blockingqueue simplifies the problem. Through this article we learn how to use Blockingqueue in Java to solve producer-consumer problems.

  15. Java thread pool (thread pool)

    The Java thread pool is a collection of worker threads waiting to process tasks, and the executor framework introduced in JAVA5 makes it easy to create a thread pool in Java using Executors and Threadpoolexecutor classes. This article learns how to use them to create a thread pool in Java.

  16. Java Callback properties (callable future)

    Sometimes we want the thread to return the available variables, JAVA5 callable can be used in this case, like runnable interface, we can use executor frame star these tasks.

  17. Java Futuretask Instance (futuretask Example)

    The Futuretask class is the base class for implementing the Future interface. Asynchronous processing is performed using the callable implementation and the executors Futuretask. Futuretask provides an implementation method to check the status of a task, and immediately returns the value to the calling program once execution is complete. It is very convenient to overwrite the implementation of some future interfaces.

This series will continue to increase as more threads are published in the tutorial articles, so please save them as bookmarks for future use. Please let us see if we have omitted the instructions you want to learn.

Original link: journaldev translation: importnew.com - Liken
Link: http://www.importnew.com/9994.html

Java threading and multithreaded tutorials

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.