[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

CN111625332A - Java thread pool rejection policy execution method and device and computer equipment - Google Patents

Java thread pool rejection policy execution method and device and computer equipment Download PDF

Info

Publication number
CN111625332A
CN111625332A CN202010438894.8A CN202010438894A CN111625332A CN 111625332 A CN111625332 A CN 111625332A CN 202010438894 A CN202010438894 A CN 202010438894A CN 111625332 A CN111625332 A CN 111625332A
Authority
CN
China
Prior art keywords
thread
task
thread pool
available processing
persistent
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202010438894.8A
Other languages
Chinese (zh)
Inventor
张新龙
范渊
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
DBAPPSecurity Co Ltd
Hangzhou Dbappsecurity Technology Co Ltd
Original Assignee
Hangzhou Dbappsecurity Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hangzhou Dbappsecurity Technology Co Ltd filed Critical Hangzhou Dbappsecurity Technology Co Ltd
Priority to CN202010438894.8A priority Critical patent/CN111625332A/en
Publication of CN111625332A publication Critical patent/CN111625332A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/48Program initiating; Program switching, e.g. by interrupt
    • G06F9/4806Task transfer initiation or dispatching
    • G06F9/4843Task transfer initiation or dispatching by program, e.g. task dispatcher, supervisor, operating system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5005Allocation of resources, e.g. of the central processing unit [CPU] to service a request
    • G06F9/5027Allocation of resources, e.g. of the central processing unit [CPU] to service a request the resource being a machine, e.g. CPUs, Servers, Terminals

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The application relates to a Java thread pool rejection policy execution method, a Java thread pool rejection policy execution device, computer equipment and a storage medium. According to the method, through the persistent task thread, under the condition that available processing resources exist in the thread pool, the anti-persistent task thread is added to the available processing resources, so that the task thread is not discarded, and the original thread can be executed orderly and safely.

Description

Java thread pool rejection policy execution method and device and computer equipment
Technical Field
The present application relates to the field of data processing technologies, and in particular, to a java thread pool rejection policy execution method, apparatus, computer device, and storage medium.
Background
In object-oriented programming, creating and destroying objects consumes a lot of time and resources, and more so in Java, the virtual machine will try to track each object in order to be able to garbage collect after the object is destroyed. In order to reduce the times of creating and destroying objects as much as possible, especially the creating and destroying of objects with larger resource consumption, how to use the existing objects to serve more thread tasks, a technology of a multi-thread pool appears in Java. The existing Java multithreading thread pool mainly comprises three parts, namely a working thread, a buffer queue and a rejection strategy. When a task is added to the thread pool, if an idle working thread exists in the thread pool, the task is operated by the working thread; under the condition of no idle working thread, the task is stored in a buffer queue, and the current task of the working thread is waited to be operated; in the case where there are no idle work threads and the buffer queue is full, then the thread pool has a corresponding rejection policy to handle these tasks.
The Java-based thread pool rejection strategy in the related art has four kinds, which are respectively:
1. the exception policy AbortPolicy does not run the task thread and only throws out the exception;
2. the caller runs policy CallerRunsPolicy, the caller runs the policy and calls the thread pool to run the task thread rejected in the working thread that is running at present, if there is no working thread that is running at present, abandon the task thread directly;
3. discarding the strategy DiscardPolicy, wherein the discarding strategy directly discards the task thread;
4. the oldest cast-off policy, DiscardOldestPolicy, is created by casting off the task thread that was added earliest in the buffer queue and then adding the rejected task thread to the buffer queue.
However, the rejection policy is implemented by throwing an exception, interrupting a current working thread, or discarding a rejected task thread, which often causes problems such as program error, incomplete execution of the task thread, and the like.
Aiming at the problems that in the related art, a Java multithreading thread pool rejection strategy can cause program errors and threads are discarded, an effective solution is not provided at present.
Disclosure of Invention
In view of the foregoing, it is desirable to provide a Java thread pool denial policy execution method, apparatus, computer device, and storage medium.
According to one aspect of the invention, a method for rejecting policy execution by a Java thread pool is provided, which comprises the following steps:
a persistent task thread;
in the event that there are available processing resources in the thread pool, the task thread is de-persisted and added to the available processing resources.
In one embodiment, the persistent task thread comprises:
obtaining a persistent path;
serializing the task thread object to obtain a byte stream;
and outputting the byte stream to the persistent path in a task file form through an object output stream.
In one embodiment, the task files are named according to a Universally Unique Identifier (UUID).
In one embodiment, the universally unique identification UUID is generated from a random number, or pseudo-random number.
In one embodiment, before deserializing the task thread and adding to the available processing resources in the case that there are available processing resources in the thread pool, the method further comprises:
and periodically detecting the state of the thread pool.
In one embodiment, the available processing resources include idle threads or queuing queue slack.
According to another aspect of the present invention, there is also provided a Java thread pool rejection policy enforcement device, the device comprising a persistence module and a de-persistence module,
the persistence module is used for persisting task threads;
the anti-persistence module is configured to, in the event that there is an available processing resource in the thread pool, anti-persist the task thread and add to the available processing resource.
In one embodiment, the apparatus further comprises a serialization module:
the serialization module is used for acquiring a persistence path;
serializing the task thread object to obtain a byte stream;
and outputting the byte stream to the persistent path in a task file form through an object output stream.
According to another aspect of the present invention, there is also provided a computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the following steps when executing the computer program:
a persistent task thread;
in the event that there are available processing resources in the thread pool, the task thread is de-persisted and added to the available processing resources.
In one embodiment, the processor, when executing the computer program, performs the steps of:
obtaining a persistent path;
serializing the task thread object to obtain a byte stream;
and outputting the byte stream to the persistent path in a task file form through an object output stream.
In one embodiment, the processor, when executing the computer program, performs the steps of: and naming the task file according to the universal unique identifier UUID.
In one embodiment, the processor, when executing the computer program, performs the steps of: and generating the UUID (universally unique identifier) according to the random number or the pseudo-random number.
In one embodiment, the processor, when executing the computer program, performs the steps of:
periodically detecting the state of the thread pool; in the event that there are available processing resources in the thread pool, the task threads are deserialized and added to the available processing resources.
According to another aspect of the present invention, there is also provided a computer readable storage medium having stored thereon a computer program which, when executed by a processor, performs the steps of:
a persistent task thread;
in the event that there are available processing resources in the thread pool, the task thread is de-persisted and added to the available processing resources.
In one embodiment, the computer program when executed by a processor implements the steps of:
obtaining a persistent path;
serializing the task thread object to obtain a byte stream;
and outputting the byte stream to the persistent path in a task file form through an object output stream.
In one embodiment, the computer program when executed by a processor implements the steps of: and naming the task file according to the universal unique identifier UUID.
In one embodiment, the computer program when executed by a processor implements the steps of: and generating the UUID (universally unique identifier) according to the random number or the pseudo-random number.
In one embodiment, the computer program when executed by a processor implements the steps of:
periodically detecting the state of the thread pool; in the event that there are available processing resources in the thread pool, the task threads are deserialized and added to the available processing resources.
According to the Java thread pool denial strategy execution method, device, computer equipment and storage medium, through the persistent task thread, under the condition that the available processing resources exist in the thread pool, the anti-persistent task thread is added to the available processing resources, so that the task thread is not discarded, and the original thread can be executed orderly and safely.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiment(s) of the application and together with the description serve to explain the application and not to limit the application. In the drawings:
FIG. 1 is a flow chart of a java thread pool rejection policy enforcement method in one embodiment of the invention;
FIG. 2 is a flowchart of a java thread pool rejection policy enforcement method according to an embodiment of the invention;
FIG. 3 is a flow chart of a java thread pool rejection policy enforcement method flow chart three in accordance with one embodiment of the present invention;
FIG. 4 is a flow diagram of a method for rejecting policy enforcement by a java thread pool in accordance with a specific embodiment of the present invention;
FIG. 5 is a block diagram of a java thread pool rejection policy enforcement device I according to one embodiment of the present invention;
FIG. 6 is a block diagram of a java thread pool rejection policy enforcement device, according to one embodiment of the present invention;
FIG. 7 is a diagram of a java thread pool rejection policy enforcement computer device architecture in accordance with one embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the present application will be described and illustrated below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the present application and are not intended to limit the present application. All other embodiments obtained by a person of ordinary skill in the art based on the embodiments provided in the present application without any inventive step are within the scope of protection of the present application.
It is obvious that the drawings in the following description are only examples or embodiments of the present application, and that it is also possible for a person skilled in the art to apply the present application to other similar contexts on the basis of these drawings without inventive effort. Moreover, it should be appreciated that in the development of any such actual implementation, as in any engineering or design project, numerous implementation-specific decisions must be made to achieve the developers' specific goals, such as compliance with system-related and business-related constraints, which may vary from one implementation to another.
Reference in the specification to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment can be included in at least one embodiment of the specification. The appearances of the phrase in various places in the specification are not necessarily all referring to the same embodiment, nor are separate or alternative embodiments mutually exclusive of other embodiments. Those of ordinary skill in the art will explicitly and implicitly appreciate that the embodiments described herein may be combined with other embodiments without conflict.
Unless defined otherwise, technical or scientific terms referred to herein shall have the ordinary meaning as understood by those of ordinary skill in the art to which this application belongs. Reference to "a," "an," "the," and similar words throughout this application are not to be construed as limiting in number, and may refer to the singular or the plural. The present application is directed to the use of the terms "including," "comprising," "having," and any variations thereof, which are intended to cover non-exclusive inclusions; for example, a process, method, system, article, or apparatus that comprises a list of steps or modules (elements) is not limited to the listed steps or elements, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus. Reference to "connected," "coupled," and the like in this application is not intended to be limited to physical or mechanical connections, but may include electrical connections, whether direct or indirect. The term "plurality" as referred to herein means two or more. "and/or" describes an association relationship of associated objects, meaning that three relationships may exist, for example, "A and/or B" may mean: a exists alone, A and B exist simultaneously, and B exists alone. The character "/" generally indicates that the former and latter associated objects are in an "or" relationship. Reference herein to the terms "first," "second," "third," and the like, are merely to distinguish similar objects and do not denote a particular ordering for the objects.
In the process of Java Thread processing, each Thread needs to create and run a Thread in a new Thread (xxRunnable) start () manner, and a real environment may open multiple threads to make a system and a program reach an optimal efficiency, when the number of threads reaches a certain number, CPU and memory resources of the system are exhausted, and frequent collection and pause of Garbage Collection (GC) are also caused, because creating and destroying a Thread each time consumes system resources, if creating a Thread for each task is a large performance bottleneck. Therefore, the reuse of the threads in the thread pool greatly saves system resources, and the threads can be automatically destroyed when no task is processed for a period of time, so that the threads cannot stay in the memory for a long time.
The thread pool has several different workflows, for example, when the number of threads in the thread pool is less than the number of threads corePoolSize maintained by the thread pool for a long time, a new thread is created to directly execute tasks; when the thread in the thread pool is larger than the corePoolSize, temporarily storing the task into a queuing queue for waiting to be executed; when the workQueue is full, a new thread is created to process when the thread number is less than the maximum thread pool number maximumpool size, and a rejection strategy is executed when the thread number is greater than or equal to the maximum thread pool number maximumpool size.
RejectedExecutionHandler provides four ways to handle task rejection policies, where DiscardPolicy drops task threads directly, DiscardOldestPolicy drops the oldest task in the queue, AbortPolicy throws an exception, CallerRunsPolicy dispatches tasks to calling threads for execution. These four strategies are independent and independent, and are four expressions to task rejection processing. The simplest way is to directly discard the task, and there are two ways to directly discard the task: DiscardPolicy discards the task itself that is currently going to be enqueued, and DiscardOldestPolicy discards the oldest task in the task queue. Instead of dropping tasks, it is also possible to simply throw an exception directly (objectedexecutionexception) in a way that, although simpler to implement, throwing a RuntimeException interrupts the caller's process. Instead of throwing exceptions, it may be possible to do without entering the thread pool, where the task in CallerRunsPolicy will be executed with the caller thread.
The Java thread pool rejection strategy execution method provided by the application provides a rejection strategy different from the four rejection strategies, and by means of the persistent task thread, when available processing resources exist in the thread pool, the task thread is deserialized and added into the thread pool, so that the task thread is not discarded, and the original thread can be orderly and safely executed.
In an embodiment, fig. 1 is a flowchart of a Java thread pool rejection policy execution method in an embodiment of the present invention, and as shown in fig. 1, there is provided a Java thread pool rejection policy execution method, including:
step S110, the task thread is persisted. In the event that a task thread is added to the thread pool and a thread pool rejection policy is triggered, the task thread is persisted. The persistence in Java refers to a process of storing byte data in a memory into a disk file, and the persistent data can be continuously accessed after the interruption and restart of the Java process. The persistence of the Java object may be achieved by: serialization techniques, extensible markup language xml file techniques, and database techniques. All object data can be stored through a serialization technology, the private data can be controlled, and the read-write data structure is strict; data in almost any form can be saved using xml file technology; the database technology can only store the data received by the database, but the reading and writing speed is high, so that the method is suitable for the condition of large data volume;
and step S120, under the condition that the available processing resources exist in the thread pool, the task threads are reversely persisted and are added into the thread pool. After the task thread can be persisted, the rejection policy task will also monitor the thread pool in real time, check whether there are available processing resources in the thread pool, and the available processing resources include various types of resources allowed to join the task thread. Optionally, the available processing resources include idle threads or queuing queue spare bits, according to the definition of the existing common java thread pool. And under the condition that available processing resources exist in the thread pool, the task thread is de-persisted, namely the task thread is taken out from the persisted path, put into the memory again and added into the available processing resources.
According to the Java thread pool strategy rejection executing method, through the persistent task thread, under the condition that the available processing resources exist in the thread pool, the anti-persistent task thread is added to the available processing resources, the current caller task is not interrupted, any task is not discarded, the exception is not thrown out, the task thread is not thrown out, and meanwhile, the original thread can be orderly and safely executed.
In one embodiment, fig. 2 is a flowchart of a java thread pool rejection policy execution method in one embodiment of the present invention, and as shown in fig. 2, a persistent task thread includes:
step S210, obtaining a persistent path;
step S220, serializing the task thread objects to obtain a byte stream;
and step S230, outputting the byte stream to a persistent path in a task file form through the object output stream.
In steps S210 to S230, a way of task thread persistence is provided. In step S210, the obtained persistent path is preset as a rejection policy initialization parameter. The serialization process in step S220 is to write the object into the byte stream. After converting the object state into a byte stream, it can be saved into a file with various byte stream classes in the java. In the embodiment, the persistence of the task thread is realized in a serialization mode, so that all object data can be stored in the persistence process of the task thread, and the persistence process of the task thread is controllable on private data, simple to realize, strict in data reading and writing structure, convenient to analyze and higher in efficiency.
In one embodiment, the task files are named according to a Universal Unique Identifier (UUID). A UUID is a machine-generated identifier that is unique within a certain range. The complex nature of UUIDs, while guaranteeing their uniqueness, means that they can only be generated by a computer, and not manually specified. A UUID is a 16-byte 128-bit long number, typically represented as a 36-byte string. The UUID may be generated based on a timestamp of file creation, file name, etc. Through the mode in the embodiment, the generated file name of the persistent file is unique, and when available processing resources exist in the thread pool, the corresponding persistent file can be found more efficiently, and the state of the persistent file is recovered and added to the thread pool. In one embodiment, the UUID is generated according to a random number or a pseudo-random number, and the generation efficiency of the persistent file can be further improved without acquiring the current time or the file name of the file.
In one embodiment, fig. 3 is a flowchart of a java thread pool rejection policy execution method in one embodiment of the present invention, where, as shown in fig. 3, in a case where there is an available processing resource in the thread pool, a task thread is de-persisted and added to the available processing resource, the method further includes:
step S310, the state of the periodic thread pool.
In step S310, the rejection policy includes a task for periodically detecting the state of the thread pool, optionally, the period of the monitoring task is one of initialization parameters of the rejection policy, and when the rejection policy is executed, the monitoring task at that time is simultaneously invoked to continuously monitor the state of the thread pool at a preset period, and when the available processing resource exists in the thread pool, the task thread is obtained and added to the available processing resource. Since real-time monitoring will consume larger monitoring resources, in this embodiment, the monitoring period parameters of the resource pool are increased, and the monitoring resources are reduced through the preset monitoring period.
In a specific embodiment, fig. 4 is a flowchart of a java thread pool rejection policy enforcement method according to a specific embodiment of the present invention, and as shown in fig. 4, the java thread pool rejection policy enforcement method includes the following steps:
step S402, a thread pool is created. The java thread pool rejection strategy provided by the invention is used as a thread pool default rejection strategy, and initialization parameters are added: output path of persistent file, and timing task execution cycle;
step S404, adding task threads to a thread pool;
step S406, judging whether the task thread is rejected to be added;
step S408, if the task thread is not rejected, adding the task thread to a thread pool;
step S410, if the addition is refused, a refusing strategy is executed;
step S412, rejecting the policy persistence task thread: randomly generating a UUID as a file name to prevent the file name from being repeated, and outputting the current thread object to a persistent path in the initialization parameter in the step S410 in a file form through an object output stream;
step S414, when executing the rejection strategy for the first time, waking up the timing task, and continuously monitoring the thread pool state according to the execution period in the initialization parameter in the step S410;
step S412, judging whether the thread pool has an idle working thread or not, or whether the buffer queue has a spare bit or not, and if so, feeding back to a rejection strategy;
in step S416, when a task thread can be added to a work thread or a buffer queue in the thread pool, the rejection policy periodically traverses all persistent files in the persistent path of the initialization parameter in step S410, deserializes the persistent files into a task thread, restores the state of the task thread, and adds the task thread to the thread pool until no more persistent files exist in the persistent path.
The java thread pool rejection strategy execution method is characterized in that aiming at the four situations, a new thread pool rejection strategy is provided, under the condition that no idle thread exists in a thread pool and a buffer queue is full, the rejection strategy stores rejected task threads to a local disk through a serialization technology, the process is the persistence of the task threads, then through detecting the thread state, when a working thread is idle or the buffer queue is empty, the task threads in the disk are restored to a memory space through a deserialization technology and are added to the thread pool. Therefore, the thread is not discarded, the program does not throw exception, and all task threads can be completely and orderly executed.
It should be understood that although the various steps in the flow charts of fig. 1-4 are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and described, and may be performed in other orders, unless explicitly stated otherwise. Moreover, at least some of the steps in fig. 1-4 may include multiple sub-steps or multiple stages that are not necessarily performed at the same time, but may be performed at different times, and the order of performance of the sub-steps or stages is not necessarily sequential, but may be performed in turn or alternating with other steps or at least some of the sub-steps or stages of other steps.
In one embodiment, fig. 5 is a block diagram of a Java thread pool rejection policy enforcement device in accordance with one embodiment of the present invention, i.e., as shown in fig. 5, there is provided a Java thread pool rejection policy enforcement device 50, which includes a persistence module 52 and a de-persistence module 54:
the persistence module 52 is used to persist task threads;
the de-persistence module 54 is used to de-persist task threads and add to available processing resources in the event that there are available processing resources in the thread pool.
In one embodiment, fig. 6 is a block diagram of a Java thread pool rejection policy enforcement device according to an embodiment of the present invention, and as shown in fig. 6, the Java thread pool rejection policy enforcement device 50 further includes a serialization module 62:
the serialization module 62 is used for obtaining a persistent path; serializing the task thread object to obtain a byte stream; and outputting the byte stream to a persistent path in the form of a task file through the object output stream.
For specific limitations of the Java thread pool rejection policy enforcement device, reference may be made to the above limitations of the Java thread pool rejection policy enforcement method, which are not described herein again. The modules in the Java thread pool rejection policy execution apparatus may be implemented in whole or in part by software, hardware, or a combination thereof. The modules can be embedded in a hardware form or independent from a processor in the computer device, and can also be stored in a memory in the computer device in a software form, so that the processor can call and execute operations corresponding to the modules.
According to the Java thread pool rejection strategy execution device, through the persistent task thread, under the condition that the available processing resources exist in the thread pool, the persistent task thread is reversed and added to the available processing resources, so that the original thread can be orderly and safely executed while the task thread is not discarded.
In one embodiment, a computer device is provided, and fig. 7 is a block diagram of a java thread pool rejection policy enforcement computer device according to one embodiment of the present invention, which may be a terminal as shown in fig. 7. The computer device includes a processor, a memory, a network interface, a display screen, and an input device connected by a system bus. Wherein the processor of the computer device is configured to provide computing and control capabilities. The memory of the computer device comprises a nonvolatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of an operating system and computer programs in the non-volatile storage medium. The network interface of the computer device is used for communicating with an external terminal through a network connection. The computer program is executed by a processor to implement a Java thread pool rejection policy execution method. The display screen of the computer equipment can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer equipment can be a touch layer covered on the display screen, a key, a track ball or a touch pad arranged on the shell of the computer equipment, an external keyboard, a touch pad or a mouse and the like.
According to the Java thread pool refusing strategy execution computer equipment, through the persistent task thread, under the condition that the available processing resource exists in the thread pool, the persistent task thread is reversed and added to the available processing resource, so that the task thread is not discarded, and the original thread can be orderly and safely executed.
Those skilled in the art will appreciate that the architecture shown in fig. 7 is merely a block diagram of some of the structures associated with the disclosed aspects and is not intended to limit the computing devices to which the disclosed aspects apply, as particular computing devices may include more or less components than those shown, or may combine certain components, or have a different arrangement of components.
In one embodiment, a computer device is provided, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, the processor implementing the following steps when executing the computer program:
a persistent task thread;
in the event that there are available processing resources in the thread pool, the task thread is de-persisted and added to the available processing resources.
In one embodiment, the processor, when executing the computer program, performs the steps of:
obtaining a persistent path;
serializing the task thread object to obtain a byte stream;
and outputting the byte stream to a persistent path in the form of a task file through the object output stream.
In one embodiment, the processor, when executing the computer program, performs the steps of: and naming the task file according to the universal unique identifier UUID.
In one embodiment, the processor, when executing the computer program, performs the steps of: and generating the UUID (universally unique identifier) according to the random number or the pseudo-random number.
In one embodiment, the processor, when executing the computer program, performs the steps of:
periodically detecting the state of a thread pool;
in the event that there are available processing resources in the thread pool, the task thread is de-persisted and added to the available processing resources.
According to the Java thread pool refusing strategy execution computer equipment, through the persistent task thread, under the condition that the available processing resource exists in the thread pool, the persistent task thread is reversed and added to the available processing resource, so that the task thread is not discarded, and the original thread can be orderly and safely executed.
In one embodiment, a computer-readable storage medium is provided, having a computer program stored thereon, which when executed by a processor, performs the steps of:
a persistent task thread;
in the event that there are available processing resources in the thread pool, the task thread is de-persisted and added to the available processing resources.
In one embodiment, the computer program when executed by the processor performs the steps of:
obtaining a persistent path;
serializing the task thread object to obtain a byte stream;
and outputting the byte stream to a persistent path in the form of a task file through the object output stream.
In one embodiment, the computer program when executed by the processor performs the steps of: and naming the task file according to the universal unique identifier UUID.
In one embodiment, the computer program when executed by the processor performs the steps of: and generating the UUID (universally unique identifier) according to the random number or the pseudo-random number.
In one embodiment, the computer program when executed by the processor performs the steps of:
periodically detecting the state of a thread pool;
in the event that there are available processing resources in the thread pool, the task thread is de-persisted and added to the available processing resources.
The Java thread pool refuses the strategy to execute the computer readable storage medium, and through the persistent task thread, under the condition that the available processing resources exist in the thread pool, the persistent task thread is reversed and added to the available processing resources, so that the original threads can be executed orderly and safely while the task threads are not discarded.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by hardware instructions of a computer program, which can be stored in a non-volatile computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. Any reference to memory, storage, database, or other medium used in the embodiments provided herein may include non-volatile and/or volatile memory, among others. Non-volatile memory can include read-only memory (ROM), Programmable ROM (PROM), Electrically Programmable ROM (EPROM), Electrically Erasable Programmable ROM (EEPROM), or flash memory. Volatile memory can include Random Access Memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in a variety of forms such as Static RAM (SRAM), Dynamic RAM (DRAM), Synchronous DRAM (SDRAM), Double Data Rate SDRAM (DDRSDRAM), Enhanced SDRAM (ESDRAM), Synchronous Link DRAM (SLDRAM), Rambus Direct RAM (RDRAM), direct bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
The technical features of the above embodiments can be arbitrarily combined, and for the sake of brevity, all possible combinations of the technical features in the above embodiments are not described, but should be considered as the scope of the present specification as long as there is no contradiction between the combinations of the technical features.
The above-mentioned embodiments only express several embodiments of the present application, and the description thereof is more specific and detailed, but not construed as limiting the scope of the invention. It should be noted that, for a person skilled in the art, several variations and modifications can be made without departing from the concept of the present application, which falls within the scope of protection of the present application. Therefore, the protection scope of the present patent shall be subject to the appended claims.

Claims (10)

1. A Java thread pool rejection policy execution method, the method comprising:
a persistent task thread;
in the event that there are available processing resources in the thread pool, the task thread is de-persisted and added to the available processing resources.
2. The method of claim 1, wherein the persistent task thread comprises:
obtaining a persistent path;
serializing the task thread object to obtain a byte stream;
and outputting the byte stream to the persistent path in a task file form through an object output stream.
3. The method of claim 2, wherein the task files are named according to a Universally Unique Identifier (UUID).
4. The method of claim 3, wherein the Universally Unique Identification (UUID) is generated based on a random number or a pseudo-random number.
5. The method of claim 1, wherein before de-persisting the task thread and adding to an available processing resource in the event that the available processing resource exists in a thread pool, the method further comprises:
and periodically detecting the state of the thread pool.
6. The method of any of claims 1 to 5, wherein the available processing resources comprise idle threads or queued queue spare bits.
7. A Java thread pool rejection policy execution apparatus, comprising a persistence module and a de-persistence module
The persistence module is used for persisting task threads;
the anti-persistence module is configured to, in the event that there is an available processing resource in the thread pool, anti-persist the task thread and add to the available processing resource.
8. The apparatus of claim 7, further comprising a serialization module to:
the serialization module is used for acquiring a persistence path;
serializing the task thread object to obtain a byte stream;
and outputting the byte stream to the persistent path in a task file form through an object output stream.
9. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the steps of the method of any of claims 1 to 6 are implemented when the computer program is executed by the processor.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 6.
CN202010438894.8A 2020-05-21 2020-05-21 Java thread pool rejection policy execution method and device and computer equipment Pending CN111625332A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010438894.8A CN111625332A (en) 2020-05-21 2020-05-21 Java thread pool rejection policy execution method and device and computer equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010438894.8A CN111625332A (en) 2020-05-21 2020-05-21 Java thread pool rejection policy execution method and device and computer equipment

Publications (1)

Publication Number Publication Date
CN111625332A true CN111625332A (en) 2020-09-04

Family

ID=72271922

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010438894.8A Pending CN111625332A (en) 2020-05-21 2020-05-21 Java thread pool rejection policy execution method and device and computer equipment

Country Status (1)

Country Link
CN (1) CN111625332A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112364100A (en) * 2020-11-06 2021-02-12 聚好看科技股份有限公司 Server and server cache persistence method
CN112835704A (en) * 2021-03-26 2021-05-25 中国工商银行股份有限公司 Task processing method, thread pool management method, device and computing equipment

Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1952881A (en) * 2002-08-14 2007-04-25 日本电信电话株式会社 Object state transfer method, object state transfer device, object state transfer program, and recording medium for the program
CN101082866A (en) * 2007-06-13 2007-12-05 北京北大方正电子有限公司 Serializing storage of objects and recovering system and method thereof
CN101599027A (en) * 2009-06-30 2009-12-09 中兴通讯股份有限公司 A kind of thread pool management method and system thereof
CN102004741A (en) * 2009-09-01 2011-04-06 上海杉达学院 Database access system
CN103399856A (en) * 2013-07-01 2013-11-20 北京科东电力控制系统有限责任公司 Explosive type data caching and processing system for SCADA system and method thereof
CN103955401A (en) * 2014-04-29 2014-07-30 南京新模式软件集成有限公司 Method for optimizing on-line preview of electronic document
CN105550319A (en) * 2015-12-12 2016-05-04 天津南大通用数据技术股份有限公司 Optimization method for high-concurrency persistence of cluster consistency service
CN108345499A (en) * 2018-02-01 2018-07-31 平安科技(深圳)有限公司 Unified thread pool processing method, application server and computer readable storage medium
US20190129747A1 (en) * 2017-10-30 2019-05-02 EMC IP Holding Company LLC Elastic Scaling Job Thread Pool in a Cloud Event Process Infrastructure

Patent Citations (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN1952881A (en) * 2002-08-14 2007-04-25 日本电信电话株式会社 Object state transfer method, object state transfer device, object state transfer program, and recording medium for the program
CN101082866A (en) * 2007-06-13 2007-12-05 北京北大方正电子有限公司 Serializing storage of objects and recovering system and method thereof
CN101599027A (en) * 2009-06-30 2009-12-09 中兴通讯股份有限公司 A kind of thread pool management method and system thereof
CN102004741A (en) * 2009-09-01 2011-04-06 上海杉达学院 Database access system
CN103399856A (en) * 2013-07-01 2013-11-20 北京科东电力控制系统有限责任公司 Explosive type data caching and processing system for SCADA system and method thereof
CN103955401A (en) * 2014-04-29 2014-07-30 南京新模式软件集成有限公司 Method for optimizing on-line preview of electronic document
CN105550319A (en) * 2015-12-12 2016-05-04 天津南大通用数据技术股份有限公司 Optimization method for high-concurrency persistence of cluster consistency service
US20190129747A1 (en) * 2017-10-30 2019-05-02 EMC IP Holding Company LLC Elastic Scaling Job Thread Pool in a Cloud Event Process Infrastructure
CN108345499A (en) * 2018-02-01 2018-07-31 平安科技(深圳)有限公司 Unified thread pool processing method, application server and computer readable storage medium

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
唐富强;于鸿洋;张萍;: "Linux下通用线程池的改进与实现", no. 28, pages 77 - 83 *
杨健等: "《Java程序设计》", vol. 1, 31 August 2016, 北京邮电大学出版社, pages: 156 - 158 *
狄振强、徐培松: "异构环境下空闲计算资源的共享与聚集", no. 16, pages 264 - 266 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN112364100A (en) * 2020-11-06 2021-02-12 聚好看科技股份有限公司 Server and server cache persistence method
CN112835704A (en) * 2021-03-26 2021-05-25 中国工商银行股份有限公司 Task processing method, thread pool management method, device and computing equipment

Similar Documents

Publication Publication Date Title
Jeffay et al. Accounting for interrupt handling costs in dynamic priority task systems
KR101146359B1 (en) Multithreaded processor with lock indicator
US9003410B2 (en) Abstracting a multithreaded processor core to a single threaded processor core
CN111427751B (en) Method and system for processing business based on asynchronous processing mechanism
CN108319495B (en) Task processing method and device
US20020174166A1 (en) Method and apparatus for reconfigurable thread scheduling unit
CN111625332A (en) Java thread pool rejection policy execution method and device and computer equipment
CN111565154B (en) Image identification request processing method and device, computer equipment and storage medium
CN111414256A (en) Application program process derivation method, system and medium based on kylin mobile operating system
US20110167428A1 (en) Busy-wait time for threads
CN110990132A (en) Asynchronous task processing method and device, computer equipment and storage medium
CN111831414A (en) Thread migration method and device, storage medium and electronic equipment
US9582340B2 (en) File lock
US6886112B2 (en) Recovering from device failure
US11588747B2 (en) Systems and methods for providing lockless bimodal queues for selective packet capture
CN113900896B (en) Method, device, equipment and storage medium for monitoring code operation
US20060143616A1 (en) System and method for performing multi-task processing
US20240231847A9 (en) Java bytecode injection methods and apparatuses, electronic devices, and storage media
CN113806065A (en) Data processing method, device and storage medium
CN106815061B (en) Service processing method and device
CN113220429B (en) Method, device, equipment and medium for processing tasks of Java thread pool
CN113835859B (en) Task scheduling method, device, equipment and readable storage medium
CN116594717A (en) Class loading isolation method, device, equipment and medium
CN113886082A (en) Request processing method and device, computing equipment and medium
US6976107B2 (en) Adaptive spin latches

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20200904

RJ01 Rejection of invention patent application after publication