1. Note: If you do not see blocking or not, this reentrantlock use means that this class is a thread-safe class.2. Thread-safe classes, blockingqueue,concurrentlinkedqueue. These are thread-safe collection classesIn Java multithreaded applications, queue usage is high, and the preferred data structure for most production consumption models is the queue.
Java-9.11 Queue
In this section, we will discuss the Queue.
The queue is very important for concurrency. Here we will just discuss it briefly and detail it later.
1. Features: first-in-first-out, which is different from the stack sequence.
2. Demo Method
Because the Queue L
Topic:Implement the following operations of a queue using stacks.
Push (x)--push element x to the back of the queue.
Pop ()--Removes the element from in front of the queue.
Peek ()--Get the front element.
Empty ()--Return whether the queue is empty.
Notes:
you must Useonly standard operat
Java thread: new feature-blocking queue is the content of the new feature of Java 5 threads. java defines the interface for blocking queues Java. util. concurrent. blockingQueue: The concept of blocking queue is that a
1. blockingqueue: two additional operations are supported. These two operations are: waiting for the queue to become non-empty when retrieving elements, and waiting for space to become available when storing elements.
2. blockingqueue does not accept null elements.
3. blockingqueue can be a limited capacity.
4. blockingqueue implementation is thread-safe. Queue is NOT thread-safe. Therefore, blockingqueue
Topic:Implement the following operations of a queue using stacks.
Push (x)--push element x to the back of the queue.
Pop ()--Removes the element from in front of the queue.
Peek ()--Get the front element.
Empty ()--Return whether the queue is empty.
Notes:
You must use only standard
The CLH queue is always mentioned in the previous blogs, and in Aqs the CLH queue is a strictly FIFO-based queue that maintains a set of threads. He can ensure that there is no hunger, strict first-come-first service fairness. is the CLH queue node:In the node qnode of the CLH queu
Collection Family Map---| Collection: Single-column collection ---| List: With storage order, repeatable ---| ArrayList: array implementation, Find Fast, and delete slow ---| LinkedList: linked list implementation, delete fast, find slow implementation of the stack queue ---| Vector: Same principle as ArrayList, but thread-safe, slightly less
Implement the following operations of a stack using queues.
Push (x)-push element x onto stack.
Pop ()--Removes the element on top of the stack.
Top ()--Get the top element.
Empty ()--Return whether the stack is empty.
Notes:
You must the only standard operations of a queue – which means only push to back ,, peek/pop from front size , and is empty operations AR E valid.
Depending on your language,
Title Description:Implement the following operations of a queue using stacks.
Push (x)--push element x to the back of the queue.
Pop ()--Removes the element from in front of the queue.
Peek ()--Get the front element.
Empty ()--Return whether the queue is empty.
Notes:
You must u
-defined tool class, the previous example can be used in a different way.The late 1.6 release also provides a number of new methods in the Linklist linked list structure. As shown in.The functions of these methods and the existing methods are the same, but there are some differences, the upgrade is for a reason.The difference needs to know which method is clearly used when developing.GetFirst method has a feature, if there is nothing in the list, call
class: Allows null elements, provides additional get,remove and insert methods, which allows LinkedList to be used as a stack, queue, or two-way queue. It can be inserted and removed in the middle of the list, which is more effective than ArrayList, but there is no ArrayList in random access. If multiple threads access a list at the same time, they must implement access synchronization on their own, and a
Topic:The queue is used to sort a sequence of data (in the order of cardinality), where data for the data series (1th and 2nd) and how the queue is stored (described in article 3rd) are as follows:1) When the data series is an integer type of data, the number of bits per data in the data series does not require equal width, for example:1, 21, 12, 322, 44, 123, 23
) { $Sb.append (Curr.tostring ()). Append (","); -Curr =Curr.next; - } -Sb.deletecharat (Sb.length ()-1); ASb.append ("]"); + returnsb.tostring (); the } - $ Public voiddisplay () { the System.out.println (toString ()); the } the } the /** - * Queue class in * Like the implementation of the Stack class in the previous example, the emphasis is on conceptual entities, independent
There are many places to use in the queue.There are many examples in the real world.For example, the hospital registration system, the bank's station-to-station system, the cafeteria in line to play rice and so on. In the market, this is the line to pick up the number of equipment. Their functions are basic such as the following: 1, the system can be networked online unified issuing number. 2, the system can be wireless docking, can also be wired con
Java data structure and algorithm parsing (13)--Priority queue
In many applications, we usually need to deal with the processing object according to the priority situation, such as dealing with the highest priority object first, and then processing the object of the high level. The simplest example is when you play a game on a mobile phone, and if there is a cal
communication method to solve this problem, commonly used methods are semaphore method [1] ET. If the workaround is not perfect, the deadlock Applications in the real worldLike a restaurant, it has a chef and a waiter. The waiter must wait for the cook to prepare the food. When the chef is ready, he notifies the waiter, then the waiter will serve, then return to wait. This is an example of a task collaboration: The chef represents the producer
17.1JMS Example Overview 23317.2 writing a simple JMS application 23317.2.1 starting a JMS provider 23417.2.2 creating a JMS managed Object 23417.2.3 building all Simple examples 23517.2.4 sending a message 23517.2.5 receiving messages synchronously 23817.2.6 using message listeners to complete asynchronous message del
Java multi-thread programming, java multi-thread programming example
Notes for learning Java !!!If you have any questions or want to obtain learning resources during the learning process, join the Java learning exchange group with the group number 618528494.Let's learn
Java programming multi-thread problem example code, java multi-thread
In the previous blog posts, I have summarized some content in java concurrency. This blog post mainly starts from a problem and shows which concurrency technologies can be used to solve the problem.Description:
Simulate a scenario: It takes one se
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.