CN116795511A - Unique identifier generation method, device, computer equipment and storage medium - Google Patents

Unique identifier generation method, device, computer equipment and storage medium Download PDF

Info

Publication number
CN116795511A
CN116795511A CN202310760540.9A CN202310760540A CN116795511A CN 116795511 A CN116795511 A CN 116795511A CN 202310760540 A CN202310760540 A CN 202310760540A CN 116795511 A CN116795511 A CN 116795511A
Authority
CN
China
Prior art keywords
task
unique identifier
executed
identifier
thread
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
CN202310760540.9A
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.)
Ping An Property and Casualty Insurance Company of China Ltd
Original Assignee
Ping An Property and Casualty Insurance Company of China 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 Ping An Property and Casualty Insurance Company of China Ltd filed Critical Ping An Property and Casualty Insurance Company of China Ltd
Priority to CN202310760540.9A priority Critical patent/CN116795511A/en
Publication of CN116795511A publication Critical patent/CN116795511A/en
Pending legal-status Critical Current

Links

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
    • G06F9/4881Scheduling strategies for dispatcher, e.g. round robin, multi-level priority queues
    • 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/54Interprogram communication
    • G06F9/547Remote procedure calls [RPC]; Web services

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 embodiment of the application belongs to the technical field of data storage in artificial intelligence, and relates to a unique identifier generation method, a device, computer equipment and a storage medium, wherein the method comprises the following steps: acquiring a task to be executed; performing recognition operation on the task to be executed to obtain a task recognition result; if the task identification result is an asynchronous task, judging whether a parent thread of the task to be executed has a parent thread identifier or not; if the parent thread has the parent thread identifier, the parent thread identifier is used as the unique identifier of the task to be executed; if the parent thread does not exist the parent thread identifier, a first unique identifier is generated, and the first unique identifier is used as the unique identifier of the task to be executed. The application effectively solves the problem that the traceId cannot be generated because the asynchronous task does not pass through the applied web filter layer, and effectively improves the compatibility.

Description

Unique identifier generation method, device, computer equipment and storage medium
Technical Field
The present application relates to the field of data storage technology in artificial intelligence, and in particular, to a method, an apparatus, a computer device, and a storage medium for generating a unique identifier.
Background
A tracking identifier (traceId) for identifying a particular request ID. When a user's request enters the system, a globally unique traceId is generated at the first layer of the RPC (Remote Procedure Call ) call network, and is passed back and forth with each layer of RPC call, so that the paths called in the system by a user's request can be concatenated through the traceId.
In the existing traceId generation method, a server side application is mainly used for receiving a client interface request, and generating the traceId in a record in a traceId grid-connected request Header after an applied web filter layer intercepts the request.
However, the applicant found that the conventional traceId generation method mainly relates to the interaction scenario of the client and the server application, but for the scenario of the timing task and the multithreaded asynchronous task, there is no interface request at the network level, and the server application triggers the executed program according to a certain rule, so that the request cannot be intercepted and the traceId can be generated in the web filter layer of the application, and therefore, the conventional traceId generation method has low compatibility because the conventional traceId generation method cannot be applied to the timing task or the multithreaded asynchronous task.
Disclosure of Invention
The embodiment of the application aims to provide a unique identifier generation method, a unique identifier generation device, computer equipment and a storage medium, so as to solve the problems that the traditional traceId generation method cannot be applied to a timing task or a multithreading asynchronous task and has low compatibility.
In order to solve the above technical problems, the embodiment of the present application provides a unique identifier generating method, which adopts the following technical scheme:
acquiring a task to be executed;
performing recognition operation on the task to be executed to obtain a task recognition result;
if the task identification result is an asynchronous task, judging whether a parent thread of the task to be executed has a parent thread identifier or not;
if the parent thread has the parent thread identifier, the parent thread identifier is used as the unique identifier of the task to be executed;
if the parent thread does not exist the parent thread identifier, a first unique identifier is generated, and the first unique identifier is used as the unique identifier of the task to be executed.
Further, after the step of identifying the task to be executed to obtain a task identification result, the method further includes the following steps:
if the task identification result is a timing task, acquiring an implementation mode of the task to be identified;
and if the implementation mode is a thread pool mode, executing the step of judging whether the parent thread of the task to be executed has a parent thread identifier.
Further, after the step of acquiring the implementation manner of the task to be identified if the task identification result is a timed task, the method further includes the following steps:
if the implementation mode is a third party framework mode, intercepting a specified method by an AOP section interception mode;
generating a second unique identifier, and setting the second unique identifier into a thread memory;
and executing the business logic of the task to be executed, and clearing the second unique identifier in the thread memory after the business logic is executed.
Further, the step of generating the first unique identifier specifically includes the following steps:
the first unique identifier is generated according to a preset manner, wherein the preset manner can be an inheritance manner or a combination manner.
In order to solve the above technical problems, the embodiment of the present application further provides a unique identifier generating device, which adopts the following technical scheme:
the task acquisition module is used for acquiring a task to be executed;
the task identification module is used for carrying out identification operation on the task to be executed to obtain a task identification result;
the first recognition result module is used for judging whether a parent thread of the task to be executed has a parent thread identifier or not if the task recognition result is an asynchronous task;
the first identifier confirmation module is used for taking the father thread identifier as the unique identifier of the task to be executed if the father thread identifier exists in the father thread;
and the first identifier generation module is used for generating a first unique identifier if the parent thread does not exist in the parent thread identifier, and taking the first unique identifier as the unique identifier of the task to be executed.
Further, the device further comprises:
the second recognition result module is used for acquiring the realization mode of the task to be recognized if the task recognition result is a timing task;
and the first implementation mode module is used for executing the step of judging whether the father thread of the task to be executed has a father thread identifier if the implementation mode is a thread pool mode.
Further, the device further comprises:
the third recognition result module is used for intercepting the appointed method through an AOP section interception mode if the implementation mode is a third-party framework mode;
the second identifier generation module is used for generating a second unique identifier and setting the second unique identifier into the thread memory;
and the business logic execution module is used for executing the business logic of the task to be executed, and clearing the second unique identifier in the thread memory after the business logic is executed.
Further, the first identifier generating module includes:
the first identifier generation sub-module is used for generating the first unique identifier according to a preset mode, wherein the preset mode can be an inheritance mode or a combination mode.
In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical schemes:
comprising a memory having stored therein computer readable instructions which when executed by a processor implement the steps of the unique identifier generation method as described above.
In order to solve the above technical problems, an embodiment of the present application further provides a computer readable storage medium, which adopts the following technical schemes:
the computer readable storage medium has stored thereon computer readable instructions which when executed by a processor implement the steps of the unique identifier generation method as described above.
Compared with the prior art, the embodiment of the application has the following main beneficial effects:
the application provides a unique identifier generation method, which comprises the following steps: acquiring a task to be executed; performing recognition operation on the task to be executed to obtain a task recognition result; if the task identification result is an asynchronous task, judging whether a parent thread of the task to be executed has a parent thread identifier or not; if the parent thread has the parent thread identifier, the parent thread identifier is used as the unique identifier of the task to be executed; if the parent thread does not exist the parent thread identifier, a first unique identifier is generated, and the first unique identifier is used as the unique identifier of the task to be executed. Compared with the prior art, the method solves the problem that the traceId cannot be generated because the asynchronous task does not pass through the applied web filter layer, and is beneficial to the on-line problem checking efficiency by adding the traceId unique identifier in the log of the multi-thread asynchronous task, so that all relevant logs of the execution can be searched once only by determining the traceId of the asynchronous execution, and a developer can grasp the execution condition of the execution at one time without searching a specific log once and integrating the logs.
Drawings
In order to more clearly illustrate the solution of the present application, a brief description will be given below of the drawings required for the description of the embodiments of the present application, it being apparent that the drawings in the following description are some embodiments of the present application, and that other drawings may be obtained from these drawings without the exercise of inventive effort for a person of ordinary skill in the art.
FIG. 1 is an exemplary system architecture diagram in which the present application may be applied;
FIG. 2 is a flowchart of an implementation of a unique identifier generation method provided in accordance with a first embodiment of the present application;
FIG. 3 is a flow chart of an embodiment following step S202 in FIG. 2;
FIG. 4 is a flow chart of one embodiment after step S301 in FIG. 3;
FIG. 5 is a flow chart of one embodiment of step S205 in FIG. 2;
fig. 6 is a schematic structural diagram of a unique identifier generating device according to a second embodiment of the present application;
FIG. 7 is a schematic diagram of an embodiment of a computer device in accordance with the application.
Detailed Description
Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application belongs; the terminology used in the description of the applications herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the application; the terms "comprising" and "having" and any variations thereof in the description of the application and the claims and the description of the drawings above are intended to cover a non-exclusive inclusion. The terms first, second and the like in the description and in the claims or in the above-described figures, are used for distinguishing between different objects and not necessarily for describing a sequential or chronological order.
Reference herein to "an embodiment" means that a particular feature, structure, or characteristic described in connection with the embodiment may be included in at least one embodiment of the application. The appearances of such phrases 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 skill in the art will explicitly and implicitly appreciate that the embodiments described herein may be combined with other embodiments.
In order to make the person skilled in the art better understand the solution of the present application, the technical solution of the embodiment of the present application will be clearly and completely described below with reference to the accompanying drawings.
As shown in fig. 1, a system architecture 100 may include terminal devices 101, 102, 103, a network 104, and a server 105. The network 104 is used as a medium to provide communication links between the terminal devices 101, 102, 103 and the server 105. The network 104 may include various connection types, such as wired, wireless communication links, or fiber optic cables, among others.
The user may interact with the server 105 via the network 104 using the terminal devices 101, 102, 103 to receive or send messages or the like. Various communication client applications, such as a web browser application, a shopping class application, a search class application, an instant messaging tool, a mailbox client, social platform software, etc., may be installed on the terminal devices 101, 102, 103.
The terminal devices 101, 102, 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smartphones, tablet computers, electronic book readers, MP3 players (Moving Picture Experts Group Audio Layer III, dynamic video expert compression standard audio plane 3), MP4 (Moving Picture Experts Group Audio Layer IV, dynamic video expert compression standard audio plane 4) players, laptop and desktop computers, and the like.
The server 105 may be a server providing various services, such as a background server providing support for pages displayed on the terminal devices 101, 102, 103.
It should be noted that, the unique identifier generating method provided by the embodiment of the present application is generally executed by a server/terminal device, and accordingly, the unique identifier generating device is generally disposed in the server/terminal device.
It should be understood that the number of terminal devices, networks and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Example 1
With continued reference to fig. 2, a flowchart of an implementation of the unique identifier generation method provided in the first embodiment of the present application is shown, and for convenience of explanation, only a portion relevant to the present application is shown.
The unique identifier generation method comprises the following steps: step S201, step S202, step S203, step S204, and step S205.
In step S201, a task to be executed is acquired;
in step S202, a task to be executed is identified, and a task identification result is obtained;
in step S203, if the task identification result is an asynchronous task, determining whether a parent thread of the task to be executed has a parent thread identifier;
in step S204, if the parent thread has a parent thread identifier, the parent thread identifier is used as a unique identifier of the task to be executed;
in step S205, if the parent thread does not have a parent thread identifier, a first unique identifier is generated, and the first unique identifier is used as a unique identifier of a task to be executed.
In an embodiment of the present application, a unique identifier (traceId) is used to track application requests and responses. When an application is completed by multiple micro-service groups, traceId can help you track the entire request and response process to diagnose problems and optimize performance.
In the embodiment of the application, the method for submitting the execution task is rewritten in the custom thread pool class. In the rewriting method, a layer of packaging is carried out on the submitted task, and a run or call method for rewriting the task in the packaging class can generate a traceId in the run or call method and set in the internal memory of the thread for caching.
In the embodiment of the application, for the scene that the thread executes the asynchronous task in the thread of the user request or the RPC call, the main thread may have a traceId at the moment, so the traceId of the main thread can be obtained before the task is packaged and then provided for the asynchronous task to use, without regenerating one, the user request and the asynchronous task can be tracked by using the same unique identifier, and the log search of the whole business process is facilitated.
In the embodiment of the application, after the traceId is generated, the existing journal storage and tracking scheme can be combined to realize the collection, filtration, display and the like of the journal, thereby assisting in the development and the positioning of operation and maintenance personnel.
In an embodiment of the present application, there is provided a unique identifier generation method, including: acquiring a task to be executed; performing recognition operation on the task to be executed to obtain a task recognition result; if the task identification result is an asynchronous task, judging whether a parent thread of the task to be executed has a parent thread identifier or not; if the parent thread has the parent thread identifier, the parent thread identifier is used as a unique identifier of the task to be executed; if the parent thread does not exist the parent thread identifier, a first unique identifier is generated, and the first unique identifier is used as the unique identifier of the task to be executed. Compared with the prior art, the method solves the problem that the traceId cannot be generated because the asynchronous task does not pass through the applied web filter layer, and is beneficial to the on-line problem checking efficiency by adding the traceId unique identifier in the log of the multi-thread asynchronous task, so that all relevant logs of the execution can be searched once only by determining the traceId of the asynchronous execution, and a developer can grasp the execution condition of the execution at one time without searching a specific log once and integrating the logs.
With continued reference to fig. 3, a flowchart of one embodiment of fig. 2 following step S202 is shown, only portions relevant to the present application being shown for ease of illustration.
In some optional implementations of the present embodiment, after step S202, further includes: step S301 and step S302.
In step S301, if the task identification result is a timed task, acquiring an implementation manner of the task to be identified;
in step S302, if the implementation is a thread pool, a step of determining whether a parent thread of the task to be executed has a parent thread identifier is performed.
In the embodiment of the present application, if the task to be identified is implemented by using a thread pool (e.g., using a spring @ Schedule annotation), the implementation of the asynchronous task in steps S203 to S205 may be used for solving.
With continued reference to fig. 4, a flowchart of one embodiment of fig. 3 after step S301 is shown, only the portions relevant to the present application being shown for ease of illustration.
In some optional implementations of the present embodiment, after step S301, further includes: step S401, step S402, and step S403.
In step S401, if the implementation mode is a third party framework mode, intercepting the specified method by an AOP cut-plane interception mode;
in step S402, generating a second unique identifier, and setting the second unique identifier into the thread memory;
in step S403, the business logic of the task to be executed is executed, and after the execution of the business logic is completed, the second unique identifier in the thread memory is cleared.
In the embodiment of the application, if the task to be identified uses a third party framework (such as a Saturn framework), the framework generally uses a base class provided by the inheritance framework and realizes a specific method, and the framework can call the realization method according to rules to complete the business logic of a user. This particular method can therefore be intercepted by means of AOP. In the interception method, a traceId is generated first, and is set in the internal memory of the thread for caching, and then subsequent business logic is carried out.
With continued reference to fig. 5, a flowchart of one embodiment of step S205 of fig. 2 is shown, only the portions relevant to the present application being shown for ease of illustration.
In some optional implementations of the present embodiment, step S205 specifically includes: step S501.
In step S501, the first unique identifier is generated according to a preset manner, where the preset manner may be an inheritance manner or a combination manner.
In the embodiment of the application, in the java technology stack, the thread pool is used as a mode of implementing multithreading in a comparison specification, so that the logic of the thread pool can be extended in an inherited or combined mode.
Those skilled in the art will appreciate that implementing all or part of the processes of the methods of the embodiments described above may be accomplished by way of computer readable instructions, stored on a computer readable storage medium, which when executed may comprise processes of embodiments of the methods described above. The storage medium may be a nonvolatile storage medium such as a magnetic disk, an optical disk, a Read-Only Memory (ROM), or a random access Memory (Random Access Memory, RAM).
It should be understood that, although the steps in the flowcharts of the figures are shown in order as indicated by the arrows, these steps are not necessarily performed in order as indicated by the arrows. The steps are not strictly limited in order and may be performed in other orders, unless explicitly stated herein. Moreover, at least some of the steps in the flowcharts of the figures may include a plurality of sub-steps or stages that are not necessarily performed at the same time, but may be performed at different times, the order of their execution not necessarily being sequential, but may be performed in turn or alternately with other steps or at least a portion of the other steps or stages.
Example two
With further reference to fig. 6, as an implementation of the method shown in fig. 2 described above, the present application provides an embodiment of a unique identifier generating apparatus, which corresponds to the method embodiment shown in fig. 2, and which is particularly applicable to various electronic devices.
As shown in fig. 6, the unique identifier generating apparatus 200 of the present embodiment includes: the task acquisition module 210, the task identification module 220, the first identification result module 230, the first identifier confirmation module 240, and the first identifier generation module 250. Wherein:
a task obtaining module 210, configured to obtain a task to be executed;
the task identification module 220 is configured to perform an identification operation on a task to be executed to obtain a task identification result;
the first recognition result module 230 is configured to determine whether a parent thread of a task to be executed has a parent thread identifier if the task recognition result is an asynchronous task;
a first identifier confirmation module 240, configured to use, if the parent thread has a parent thread identifier, the parent thread identifier as a unique identifier of the task to be executed;
the first identifier generating module 250 is configured to generate a first unique identifier if the parent thread does not have a parent thread identifier, and use the first unique identifier as a unique identifier of a task to be executed.
In an embodiment of the present application, a unique identifier (traceId) is used to track application requests and responses. When an application is completed by multiple micro-service groups, traceId can help you track the entire request and response process to diagnose problems and optimize performance.
In the embodiment of the application, the method for submitting the execution task is rewritten in the custom thread pool class. In the rewriting method, a layer of packaging is carried out on the submitted task, and a run or call method for rewriting the task in the packaging class can generate a traceId in the run or call method and set in the internal memory of the thread for caching.
In the embodiment of the application, for the scene that the thread executes the asynchronous task in the thread of the user request or the RPC call, the main thread may have a traceId at the moment, so the traceId of the main thread can be obtained before the task is packaged and then provided for the asynchronous task to use, without regenerating one, the user request and the asynchronous task can be tracked by using the same unique identifier, and the log search of the whole business process is facilitated.
In the embodiment of the application, after the traceId is generated, the existing journal storage and tracking scheme can be combined to realize the collection, filtration, display and the like of the journal, thereby assisting in the development and the positioning of operation and maintenance personnel.
In an embodiment of the present application, there is provided a unique identifier generating apparatus 200, including: a task obtaining module 210, configured to obtain a task to be executed; the task identification module 220 is configured to perform an identification operation on a task to be executed to obtain a task identification result; the first recognition result module 230 is configured to determine whether a parent thread of a task to be executed has a parent thread identifier if the task recognition result is an asynchronous task; a first identifier confirmation module 240, configured to use, if the parent thread has a parent thread identifier, the parent thread identifier as a unique identifier of the task to be executed; the first identifier generating module 250 is configured to generate a first unique identifier if the parent thread does not have a parent thread identifier, and use the first unique identifier as a unique identifier of a task to be executed. Compared with the prior art, the method solves the problem that the traceId cannot be generated because the asynchronous task does not pass through the applied web filter layer, and is beneficial to the on-line problem checking efficiency by adding the traceId unique identifier in the log of the multi-thread asynchronous task, so that all relevant logs of the execution can be searched once only by determining the traceId of the asynchronous execution, and a developer can grasp the execution condition of the execution at one time without searching a specific log once and integrating the logs.
In some optional implementations of the present embodiment, the unique identifier generating device 100 further includes: the second recognition result module and the first implementation module, wherein:
the second recognition result module is used for acquiring the realization mode of the task to be recognized if the task recognition result is a timing task;
and the first implementation mode module is used for executing the step of judging whether the parent thread of the task to be executed has the parent thread identifier if the implementation mode is the thread pool mode.
In an embodiment of the present application, if the task to be identified is implemented using a thread pool (e.g., using a spring @ Schedule annotation), the asynchronous task implementation in the first identification result module 230, the first identifier validation module 240, and the first identifier generation module 250 may be used to solve.
In some optional implementations of the present embodiment, the unique identifier generating device 100 further includes: the system comprises a third identification result module, a second identifier generation module and a business logic execution module, wherein:
the third recognition result module is used for intercepting the appointed method through an AOP section interception mode if the implementation mode is a third-party framework mode;
the second identifier generation module is used for generating a second unique identifier and setting the second unique identifier into the thread memory;
and the business logic execution module is used for executing the business logic of the task to be executed, and clearing the second unique identifier in the thread memory after the business logic is executed.
In the embodiment of the application, if the task to be identified uses a third party framework (such as a Saturn framework), the framework generally uses a base class provided by the inheritance framework and realizes a specific method, and the framework can call the realization method according to rules to complete the business logic of a user. This particular method can therefore be intercepted by means of AOP. In the interception method, a traceId is generated first, and is set in the internal memory of the thread for caching, and then subsequent business logic is carried out.
In some optional implementations of this embodiment, the first identifier generating module 250 includes: a first identifier generation sub-module, wherein:
the first identifier generation sub-module is used for generating a first unique identifier according to a preset mode, wherein the preset mode can be an inheritance mode or a combination mode.
In the embodiment of the application, in the java technology stack, the thread pool is used as a mode of implementing multithreading in a comparison specification, so that the logic of the thread pool can be extended in an inherited or combined mode.
In order to solve the technical problems, the embodiment of the application also provides computer equipment. Referring specifically to fig. 7, fig. 7 is a basic structural block diagram of a computer device according to the present embodiment.
The computer device 300 includes a memory 310, a processor 320, and a network interface 330 communicatively coupled to each other via a system bus. It should be noted that only computer device 300 having components 310-330 is shown in the figures, but it should be understood that not all of the illustrated components need be implemented, and that more or fewer components may be implemented instead. It will be appreciated by those skilled in the art that the computer device herein is a device capable of automatically performing numerical calculations and/or information processing in accordance with predetermined or stored instructions, the hardware of which includes, but is not limited to, microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASICs), programmable gate arrays (fields-Programmable Gate Array, FPGAs), digital processors (Digital Signal Processor, DSPs), embedded devices, etc.
The computer equipment can be a desktop computer, a notebook computer, a palm computer, a cloud server and other computing equipment. The computer equipment can perform man-machine interaction with a user through a keyboard, a mouse, a remote controller, a touch pad or voice control equipment and the like.
The memory 310 includes at least one type of readable storage medium including flash memory, hard disk, multimedia card, card memory (e.g., SD or DX memory, etc.), random Access Memory (RAM), static Random Access Memory (SRAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), programmable Read Only Memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 310 may be an internal storage unit of the computer device 300, such as a hard disk or a memory of the computer device 300. In other embodiments, the memory 310 may also be an external storage device of the computer device 300, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash Card (Flash Card) or the like, which are provided on the computer device 300. Of course, the memory 310 may also include both internal storage units and external storage devices of the computer device 300. In this embodiment, the memory 310 is typically used to store an operating system and various types of application software installed on the computer device 300, such as computer readable instructions of a unique identifier generation method. In addition, the memory 310 may also be used to temporarily store various types of data that have been output or are to be output.
The processor 320 may be a central processing unit (Central Processing Unit, CPU), controller, microcontroller, microprocessor, or other data processing chip in some embodiments. The processor 320 is generally used to control the overall operation of the computer device 300. In this embodiment, the processor 320 is configured to execute computer readable instructions stored in the memory 310 or process data, such as computer readable instructions for executing the unique identifier generating method.
The network interface 330 may include a wireless network interface or a wired network interface, the network interface 330 typically being used to establish communication connections between the computer device 300 and other electronic devices.
The computer equipment solves the problem that the traceId cannot be generated because the asynchronous task does not pass through the applied web filter layer, and is beneficial to the on-line problem checking efficiency by adding the unique traceId identifier in the log of the multi-thread asynchronous task, so that all relevant logs executed at the time can be searched once only by determining the traceId executed at the time, and a developer can grasp the executing condition at the time integrally without searching the specific log at the time and integrating the logs.
The present application also provides another embodiment, namely, a computer-readable storage medium storing computer-readable instructions executable by at least one processor to cause the at least one processor to perform the steps of the unique identifier generation method as described above.
The computer readable storage medium solves the problem that the traceId cannot be generated because the asynchronous task does not pass through an applied web filter layer, is beneficial to the on-line problem checking efficiency by adding the unique traceId identifier in the log of the multi-thread asynchronous task, can search all relevant logs of the execution once only by determining the traceId of the asynchronous execution, and is beneficial to the developer to grasp the execution condition of the execution entirely without searching the specific log once again and again integrating.
From the above description of the embodiments, it will be clear to those skilled in the art that the above-described embodiment method may be implemented by means of software plus a necessary general hardware platform, but of course may also be implemented by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (e.g. ROM/RAM, magnetic disk, optical disk) comprising instructions for causing a terminal device (which may be a mobile phone, a computer, a server, an air conditioner, or a network device, etc.) to perform the method according to the embodiments of the present application.
It is apparent that the above-described embodiments are only some embodiments of the present application, but not all embodiments, and the preferred embodiments of the present application are shown in the drawings, which do not limit the scope of the patent claims. This application may be embodied in many different forms, but rather, embodiments are provided in order to provide a thorough and complete understanding of the present disclosure. Although the application has been described in detail with reference to the foregoing embodiments, it will be apparent to those skilled in the art that modifications may be made to the embodiments described in the foregoing description, or equivalents may be substituted for elements thereof. All equivalent structures made by the content of the specification and the drawings of the application are directly or indirectly applied to other related technical fields, and are also within the scope of the application.

Claims (10)

1. A method of generating a unique identifier, comprising the steps of:
acquiring a task to be executed;
performing recognition operation on the task to be executed to obtain a task recognition result;
if the task identification result is an asynchronous task, judging whether a parent thread of the task to be executed has a parent thread identifier or not;
if the parent thread has the parent thread identifier, the parent thread identifier is used as the unique identifier of the task to be executed;
if the parent thread does not exist the parent thread identifier, a first unique identifier is generated, and the first unique identifier is used as the unique identifier of the task to be executed.
2. The unique identifier generating method according to claim 1, further comprising, after the step of performing the identifying operation on the task to be executed to obtain a task identification result, the steps of:
if the task identification result is a timing task, acquiring an implementation mode of the task to be identified;
and if the implementation mode is a thread pool mode, executing the step of judging whether the parent thread of the task to be executed has a parent thread identifier.
3. The unique identifier generating method according to claim 2, further comprising, after the step of acquiring the implementation manner of the task to be identified if the task identification result is a timed task, the steps of:
if the implementation mode is a third party framework mode, intercepting a specified method by an AOP section interception mode;
generating a second unique identifier, and setting the second unique identifier into a thread memory;
and executing the business logic of the task to be executed, and clearing the second unique identifier in the thread memory after the business logic is executed.
4. The method for generating a unique identifier according to claim 1, wherein the step of generating a first unique identifier comprises the steps of:
the first unique identifier is generated according to a preset manner, wherein the preset manner can be an inheritance manner or a combination manner.
5. A unique identifier generating apparatus, comprising:
the task acquisition module is used for acquiring a task to be executed;
the task identification module is used for carrying out identification operation on the task to be executed to obtain a task identification result;
the first recognition result module is used for judging whether a parent thread of the task to be executed has a parent thread identifier or not if the task recognition result is an asynchronous task;
the first identifier confirmation module is used for taking the father thread identifier as the unique identifier of the task to be executed if the father thread identifier exists in the father thread;
and the first identifier generation module is used for generating a first unique identifier if the parent thread does not exist in the parent thread identifier, and taking the first unique identifier as the unique identifier of the task to be executed.
6. The unique identifier generating apparatus according to claim 5, wherein the apparatus further comprises:
the second recognition result module is used for acquiring the realization mode of the task to be recognized if the task recognition result is a timing task;
and the first implementation mode module is used for executing the step of judging whether the father thread of the task to be executed has a father thread identifier if the implementation mode is a thread pool mode.
7. The unique identifier generating apparatus according to claim 6, wherein the apparatus further comprises:
the third recognition result module is used for intercepting the appointed method through an AOP section interception mode if the implementation mode is a third-party framework mode;
the second identifier generation module is used for generating a second unique identifier and setting the second unique identifier into the thread memory;
and the business logic execution module is used for executing the business logic of the task to be executed, and clearing the second unique identifier in the thread memory after the business logic is executed.
8. The unique identifier generating apparatus according to claim 6, wherein the first identifier generating module comprises:
the first identifier generation sub-module is used for generating the first unique identifier according to a preset mode, wherein the preset mode can be an inheritance mode or a combination mode.
9. A computer device comprising a memory and a processor, the memory having stored therein computer readable instructions which when executed by the processor implement the steps of the unique identifier generation method of any of claims 1 to 4.
10. A computer readable storage medium having stored thereon computer readable instructions which when executed by a processor implement the steps of the unique identifier generation method of any of claims 1 to 4.
CN202310760540.9A 2023-06-26 2023-06-26 Unique identifier generation method, device, computer equipment and storage medium Pending CN116795511A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310760540.9A CN116795511A (en) 2023-06-26 2023-06-26 Unique identifier generation method, device, computer equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310760540.9A CN116795511A (en) 2023-06-26 2023-06-26 Unique identifier generation method, device, computer equipment and storage medium

Publications (1)

Publication Number Publication Date
CN116795511A true CN116795511A (en) 2023-09-22

Family

ID=88041682

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310760540.9A Pending CN116795511A (en) 2023-06-26 2023-06-26 Unique identifier generation method, device, computer equipment and storage medium

Country Status (1)

Country Link
CN (1) CN116795511A (en)

Similar Documents

Publication Publication Date Title
CN112860662B (en) Automatic production data blood relationship establishment method, device, computer equipment and storage medium
CN113254445B (en) Real-time data storage method, device, computer equipment and storage medium
CN111813418B (en) Distributed link tracking method, device, computer equipment and storage medium
CN117094729A (en) Request processing method, device, computer equipment and storage medium
CN116661936A (en) Page data processing method and device, computer equipment and storage medium
CN114626352B (en) Report automatic generation method, device, computer equipment and storage medium
CN116795511A (en) Unique identifier generation method, device, computer equipment and storage medium
CN115250200B (en) Service authorization authentication method and related equipment thereof
CN113806372B (en) New data information construction method, device, computer equipment and storage medium
CN116467145A (en) Page performance data acquisition method and device, computer equipment and storage medium
CN117112383A (en) Performance analysis method, device, equipment and storage medium based on artificial intelligence
CN117591190A (en) Application data loading optimization method, device, equipment and storage medium thereof
CN117579457A (en) Business logic isolation method and device, computer equipment and storage medium
CN117853241A (en) Risk service provider identification method, apparatus, device and storage medium thereof
CN116737437A (en) Data analysis method, device, computer equipment and storage medium
CN117290019A (en) Interface calling method and device, computer equipment and storage medium
CN117278263A (en) Authentication processing method, authentication processing device, computer equipment and storage medium
CN116860644A (en) Automatic test method, device, computer equipment and storage medium
CN117271156A (en) Message transmission method, device, equipment and storage medium thereof
CN117828221A (en) Page event statistics method based on buried point technology and related equipment thereof
CN117251468A (en) Query processing method, device, computer equipment and storage medium
CN117874073A (en) Search optimization method, device, equipment and storage medium thereof
CN117278623A (en) Method and device for processing request data, computer equipment and storage medium
CN116795882A (en) Data acquisition method, device, computer equipment and storage medium
CN116663003A (en) Attack detection method, attack detection device, computer equipment and storage medium

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