Write a program to simulate four ticket window programs that sell 100 train tickets together.
1: implement it by inheriting the Thread class ().2: implement the Runnable interface ().
Method 1
Package com. ljq. test;/*** Use the Thread class to
Two ways to create thread 1, extends thread this class. 2, implements runnable this interface.Set Daemon (); Create a background process; Tt.join ("a") means that a thread is released after it is added to the TT (a) MS;Advantages of using
Alibaba internal interview summary and Alibaba interview Summary
1. What is the difference between StringBuffer and StringBuilder? Assume there is a method. An object must be defined inside the method, which may be StringBuffer or StringBuilder.
[JavaSE] multithreading (ticket sales example), javase ticket sales
Requirement: simple ticket buying program, ticket selling in multiple windows, multi-thread
Define a class Ticket to implement the Runnable interface,
Defines the number of digits
package Com.loaderman.syn; public class Demo_ticket {/** * demand: railway ticketing, altogether 100, through four The window is sold out. */public static void main (string[] args) {new Ticket (). Start (); New Ticket (). Start ();
the internet is widely circulated is an online ticketing system to explain. Forwarded over. I don't know where the original text is from .There are two ways to implement multithreading in Java. The first is the direct inheritance of the thread class,
Java multi-thread synchronized
First, let's look at the next scenario. A cinema sells tickets for four windows at a time. There are only 100 tickets in total for this movie. Check the actual code.
Package cn.com. thread; public class TestThread
Shared variables for java multi-thread Communication(1) when accessing the Common Code: You can use the same Runnable object, which contains the shared data, such as the ticket selling system. Or the shared data is encapsulated in an object, and the
1. Clarify the concept of parallel and concurrency: * Parallel: Multiple CPU instances or multiple machines simultaneously execute a processing logic, is true at the same time. * Concurrency: Through the CPU scheduling algorithm, let the user appear
There are two ways to implement multithreading in Java, one is to inherit the thread class, and the other is to implement the Runnable interface.So what is the difference between inheriting the thread class and implementing the Runnable interface?
Original address: http://www.cnblogs.com/jaycekon/p/6225058.html1. Download and install ACTIVEMQACTIVEMQ Official website: http://activemq.apache.org/download.htmlActiveMQ provides several versions of Windows and Linux, Unix, and so on, the landlord
There are many ways to create multithreading in Java, here's a quick comb1. Inheriting the thread classInherit the Java.lang.Thread class, create a local multithreaded class, overload the Run () method, and invoke the thread's method to start the
On the network for thread resolution always smallpox dragon and Phoenix, to you instill a lot of concepts, postgraduate examination, undergraduate operating system, especially, so you even carefully read a lot of articles do not know what to do.The
Directory
1.1 Introduction
1.2 Performing basic atomic operations
1.3 Using the Mutex class
1.4 Using the Semaphoreslim class
1.5 Using the AutoResetEvent class
1.6 Using the ManualResetEventSlim class
1.7 Using the
Package com.thread.runnable;/*** There are two ways to implement multithreading, such as inheriting the thread class and implementing the Runnable interface.* Which way is better? The way that is implemented because of inheritance.* Reason: 1. Avoid
Basic concepts of 09_1_ threads 1.Basic concepts of threadingThe sequential control flow within a program of a thread.The difference between threads and processesseparate code and data space for each process ( process Context ) , there is a
Java Sync Lock (synchronized)in Java, synchronized is a lock, he can lock a method, can also lock a method, I wipe, in fact, these two things are the same. Block is not a method without a name, the method is a name of the block. This article uses
if each thread executes the same code, the same Runnable object can be used, and the Runnable object has that shared data, such as the ticket system.
Package com.itm.thread;
public class Multithreadsharedata {public
static void Main (string[]
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.