Java(30)
-
Java Concurrency - Thread Safe
What is Thread Safe?No matter how many threads access an object or a method in a business, when writing this business logic, there is no need to do any additional processing, and the program can also run normally, which can be called thread-safe. What is Thread Unsafe?When multiple threads access an object simultaneously, if one thread is updating the value of an object while another thread is ..
2024.10.27 -
Java Concurrency - stop(), interrupt()
How to properly stop a ThreadAfter a thread is created and started, there are some reasons to stop a thread. But it is not easy to stop the thread safely and reliably since the Java language does not have a mechanism to ensure the immediate and correct stop of the thread. However, it provides interrupt, which is a collaborative mechanism. You can use the interrupt() method to notify a thread tha..
2024.10.26 -
Delete Node in a Linked List
SolutionThere is a singly linked list head, and we want to delete a node node in it.You are given the node to be deleted node. You will not be given access to the first node of the head.All the values of the linked list are unique, and it is guaranteed that the given node is not the last node in the linked list. Delete the given node. Note that by deleting the node, we do not mean removing it fr..
2024.10.25 -
String to Integer (atoi)
SolutionImplement the myAtoi(string s) function, which converts a string to a 32-bit signed integer.The algorithm for myAtoi(string s) is as follows: Whitespace: Ignore any leading whitespace (" ").Signedness: Determine the sign by checking if the next character is '-' or '+', assuming positivity is neither present.Conversion: Read the integer by skipping leading zeros until a non-digit characte..
2024.10.22 -
Java Concurrency - Thread Priority
What is Thread Priority?The priority in the order of execution that the operating system assigns to each thread when scheduling threads. Threads with a higher priority are executed before threads with a lower priority. The default thread priority in Java is 5, and you can specify the priority of thread execution in the range 1 to 10. Generally, threads with higher priorities will have a higher c..
2024.10.20 -
Java Concurrency - Thread Group
Thread GroupA thread group represents a set of threads. In addition, a thread group can also include other thread groups. The thread groups form a tree in which every thread group except the initial thread group has a parent. The relationship between ThreadGroup and Thread is as simple as their literal meanings; each Thread necessarily exists in a ThreadGroup, and a Thread cannot exist independe..
2024.10.19