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

CN116032949B - Time synchronization method, apparatus, electronic device, and computer-readable storage medium - Google Patents

Time synchronization method, apparatus, electronic device, and computer-readable storage medium Download PDF

Info

Publication number
CN116032949B
CN116032949B CN202310314996.2A CN202310314996A CN116032949B CN 116032949 B CN116032949 B CN 116032949B CN 202310314996 A CN202310314996 A CN 202310314996A CN 116032949 B CN116032949 B CN 116032949B
Authority
CN
China
Prior art keywords
server
time
state information
state
resource
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.)
Active
Application number
CN202310314996.2A
Other languages
Chinese (zh)
Other versions
CN116032949A (en
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.)
Chengdu Shuzhilian Technology Co Ltd
Original Assignee
Chengdu Shuzhilian 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 Chengdu Shuzhilian Technology Co Ltd filed Critical Chengdu Shuzhilian Technology Co Ltd
Priority to CN202310314996.2A priority Critical patent/CN116032949B/en
Publication of CN116032949A publication Critical patent/CN116032949A/en
Application granted granted Critical
Publication of CN116032949B publication Critical patent/CN116032949B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Landscapes

  • Electric Clocks (AREA)

Abstract

The embodiment of the application provides a time synchronization method, a time synchronization device, electronic equipment and a computer readable storage medium, and relates to the technical field of communication. The corresponding relation between the state information and the synchronous operation is stored in the electronic equipment, and the state information sent by the server is received by the electronic equipment under the condition that the electronic equipment is in communication connection with the server; the state information is used for representing the current resource state of the server; determining a target synchronous operation corresponding to the state information according to the corresponding relation; by performing the target synchronization operation, the time of the electronic device is synchronized with the time of the server. By the method, the time synchronization is carried out, the influence on the performance of the server can be reduced, and the performance of the server is improved.

Description

Time synchronization method, apparatus, electronic device, and computer-readable storage medium
Technical Field
The present application relates to the field of communications technologies, and in particular, to a time synchronization method, apparatus, electronic device, and computer readable storage medium.
Background
Many applications of electronic devices currently have a time display function, and the time of display is often required to be consistent with the time of a server based on service requirements.
In the prior art, the electronic device can access the server frequently to perform time synchronization, but the method often needs to occupy certain resources, so that when the server resources are tense, the method can have a great influence on the performance of the server, and the running performance of the server is poor.
Disclosure of Invention
In view of the foregoing, an object of the present application is to provide a time synchronization method, apparatus, electronic device and computer readable storage medium, so as to solve the problem that the time synchronization in the prior art may have a large influence on the performance of a server, resulting in poor running performance of the server.
In order to achieve the above purpose, the technical solution adopted in the embodiment of the present application is as follows:
in a first aspect, the present application provides a time synchronization method, applied to an electronic device, where a correspondence between state information and a synchronization operation is stored in the electronic device, the method includes:
receiving state information sent by a server under the condition of maintaining communication connection with the server; the state information is used for representing the current resource state of the server;
determining a target synchronous operation corresponding to the state information according to the corresponding relation;
and synchronizing the time of the electronic equipment with the time of the server by executing the target synchronization operation.
In an optional implementation manner, the determining, according to the correspondence, the target synchronization operation corresponding to the state information includes:
determining a target synchronous operation corresponding to the first state information as a first synchronous operation according to the corresponding relation under the condition that the state information is the first state information; the first state information characterizes that the current resource state of the server is in a resource abundant state;
determining a target synchronous operation corresponding to the second state information as a second synchronous operation according to the corresponding relation when the state information is the second state information; the second state information characterizes that the current resource state of the server is in a first resource shortage state;
if the state information is third state information, determining a target synchronous operation corresponding to the third state information as a third synchronous operation according to the corresponding relation; the third state information characterizes that the current resource state of the server is in a second resource shortage state, and the resource shortage degree of the second resource shortage state is higher than that of the first resource shortage state.
In an alternative embodiment, the synchronizing the time of the electronic device with the time of the server by performing the target synchronization operation includes:
and under the condition that the target synchronous operation is the first synchronous operation, acquiring the time of the server at intervals of preset time, and setting the time of the electronic equipment according to the time of the server so as to synchronize the time of the electronic equipment with the time of the server.
In an alternative embodiment, the synchronizing the time of the electronic device with the time of the server by performing the target synchronization operation includes:
under the condition that the target synchronous operation is a second synchronous operation, acquiring the current time of the server, and setting the current time of the electronic equipment according to the current time of the server;
stopping sending data to the server so that the communication connection between the electronic equipment and the server is in a vacant state;
and updating the current time of the electronic equipment through a timing thread so as to synchronize the time of the electronic equipment with the time of the server.
In an alternative embodiment, the method further comprises:
and under the condition that the duration of the communication connection between the electronic equipment and the server in the idle state reaches the preset duration, disconnecting the communication connection between the electronic equipment and the server.
In an alternative embodiment, the synchronizing the time of the electronic device with the time of the server by performing the target synchronization operation includes:
acquiring the current time of the server under the condition that the target synchronous operation is a third synchronous operation, and setting the current time of the electronic equipment according to the current time of the server;
and disconnecting the communication connection between the electronic equipment and the server, and updating the current time of the electronic equipment through a timing thread so as to synchronize the time of the electronic equipment with the time of the server.
In a second aspect, the present application provides a time synchronization apparatus applied to an electronic device, where a correspondence between state information and a synchronization operation is stored in the electronic device, the apparatus includes:
the receiving module is used for receiving the state information sent by the server under the condition of keeping communication connection with the server; the state information is used for representing the current resource state of the server;
the determining module is used for determining a target synchronous operation corresponding to the state information according to the corresponding relation;
and the synchronization module is used for synchronizing the time of the electronic equipment with the time of the server by executing the target synchronization operation.
In an optional embodiment, the determining module is further configured to determine, according to the correspondence, that a target synchronization operation corresponding to the first state information is a first synchronization operation when the state information is the first state information; the first state information characterizes that the current resource state of the server is in a resource abundant state;
the determining module is further configured to determine, according to the correspondence, that a target synchronization operation corresponding to the second state information is a second synchronization operation when the state information is the second state information; the second state information characterizes that the current resource state of the server is in a first resource shortage state;
the determining module is further configured to determine, according to the correspondence, that a target synchronization operation corresponding to the third state information is a third synchronization operation when the state information is the third state information; the third state information characterizes that the current resource state of the server is in a second resource shortage state, and the resource shortage degree of the second resource shortage state is higher than that of the first resource shortage state.
In a third aspect, the present application provides an electronic device comprising a processor and a memory storing a computer program executable by the processor, the processor being executable to implement the method of any of the preceding embodiments.
In a fourth aspect, the present application provides a computer-readable storage medium, having stored thereon a computer program which, when executed by a processor, implements a method according to any of the preceding embodiments.
According to the time synchronization method, the device, the electronic equipment and the computer readable storage medium, the electronic equipment can determine the target synchronization operation corresponding to the state information sent by the server according to the corresponding relation between the state information stored in the electronic equipment and the synchronization operation, and then the time of the electronic equipment is synchronized with the time of the server by executing the synchronization operation.
In order to make the above objects, features and advantages of the present application more comprehensible, preferred embodiments accompanied with figures are described in detail below.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are needed in the embodiments will be briefly described below, it being understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered limiting the scope, and that other related drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 shows a block schematic diagram of a time synchronization system;
fig. 2 shows a block schematic diagram of an electronic device provided in an embodiment of the present application;
fig. 3 is a schematic flow chart of a time synchronization method according to an embodiment of the present application;
fig. 4 shows a functional block diagram of a time synchronization device according to an embodiment of the present application.
Icon: 10-a time synchronization system; 100-an electronic device; 101-memory; 102-a processor; 103-a communication module; 110-a server; 200-a receiving module; 210-a determination module; 220-synchronization module.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the drawings in the embodiments of the present application, and it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. The components of the embodiments of the present application, which are generally described and illustrated in the figures herein, may be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the present application, as provided in the accompanying drawings, is not intended to limit the scope of the application, as claimed, but is merely representative of selected embodiments of the application. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present application without making any inventive effort, are intended to be within the scope of the present application.
It is noted that relational terms such as "first" and "second", and the like, are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
Currently, many Web front-end applications of electronic devices have a time display function, such as a browser, and the current time may be displayed in the following manner in the prior art: 1. the electronic equipment obtains the local time of the client side for displaying; 2. the electronic equipment continuously calls the interface to frequently access the server so as to perform time synchronization; 3. and the electronic equipment counts time by using the JavaScript thread at the front end after acquiring the server time.
However, the above methods have corresponding problems, firstly, aiming at the first method, if the local time of the client is inaccurate, the display time of the browser is inaccurate, and if the display time of the electronic equipment is consistent with the display time of the server, the first acquisition method cannot meet the requirement of the actual service; secondly, aiming at the second mode, the electronic equipment needs to occupy certain server resources by continuously calling the interface to frequently access the server, so that when the server resources are tense, the method can have great influence on the performance of the server, and the running performance of the server is lower; again, with respect to the third approach, since the JavaScript thread is a single thread, if the running time is long, there may be a problem of inaccuracy in the time displayed by the electronic device.
Based on this, the embodiment of the application provides a time synchronization method to solve the above problems. Specifically, fig. 1 is a block diagram of a time synchronization system 10, please refer to fig. 1, the time synchronization system 10 includes an electronic device 100 and a server 110, and the electronic device 100 is communicatively connected to the server 110.
Alternatively, the electronic device 100 may be a PC or a mobile terminal, and the electronic device 100 may be time-synchronized with the server 110. In one possible implementation, front-end software such as a browser may be provided on the electronic device 100, and the electronic device may cause the browser to display the current time by synchronizing with the time of the server.
Alternatively, the electronic device may also have stored therein a correspondence relationship between the state information and the synchronization operation in advance. It will be appreciated that the state information characterizes the resource state of the server, and that the synchronization operation refers to how time synchronization should be performed.
Optionally, fig. 2 is a block schematic diagram of an electronic device 100 according to an embodiment of the present application, where the electronic device 100 includes a memory 101, a processor 102, and a communication module 103. The memory 101, the processor 102, and the communication module 103 are electrically connected directly or indirectly to each other to realize data transmission or interaction. For example, the components may be electrically connected to each other via one or more communication buses or signal lines.
Wherein the memory 101 is used for storing programs or data. The Memory 101 may be, but is not limited to, random access Memory (Random Access Memory, RAM), read Only Memory (ROM), programmable Read Only Memory (Programmable Read-Only Memory, PROM), erasable Read Only Memory (Erasable Programmable Read-Only Memory, EPROM), electrically erasable Read Only Memory (Electric Erasable Programmable Read-Only Memory, EEPROM), etc.
The processor 102 is used to read/write data or programs stored in the memory and perform corresponding functions.
The communication module 103 is used for establishing a communication connection between the server and other communication terminals through a network, and for transceiving data through the network.
It should be understood that the structure shown in fig. 2 is merely a schematic structural diagram of an electronic device, and that the electronic device may also include more or fewer components than those shown in fig. 2, or have a different configuration than that shown in fig. 2. The components shown in fig. 2 may be implemented in hardware, software, or a combination thereof.
Next, the time synchronization method provided in the embodiments of the present application will be exemplarily described with reference to the flowchart with the electronic device 100 as an execution body. Specifically, fig. 3 is a flow chart of a time synchronization method provided in an embodiment of the present application, please refer to fig. 3, the method includes:
step S20, receiving state information sent by a server under the condition that communication connection with the server is maintained;
the state information is used for representing the current resource state of the server;
alternatively, the electronic device may establish a communication connection with the server, for example, a WebSocket connection may be established between the browser and the server, and the electronic device may receive the status information sent by the server if it is determined that the communication connection is maintained with the server.
Optionally, the server may acquire the state information of the server in real time and send the state information to the electronic device, or may acquire the state information once every a preset time period and send the state information to the electronic device.
Alternatively, the server may acquire the state information by polling, or acquire the state information by determining the number of interface calls, or acquire the state information by an operation and maintenance monitoring tool.
In addition, the electronic device can actively acquire the resource state of the server in communication connection with the electronic device in a certain mode.
Alternatively, the status information may characterize the current resource status of the server, e.g., whether the server is currently resource-efficient or resource-starved.
In one possible implementation, the resource status may be a real-time use case of the CPU.
In one example, if the server is a Java server, various resource data of the server, such as real-time use cases of memory, CPU, and the like, may be obtained through a Sigar module.
In this example, a determination condition may be set in advance according to the service requirement, so as to determine the resource status of the server, for example, if the CPU usage is less than 80% and the memory remaining is less than 1G, then it is determined that the server is abundant in resources at this time.
Step S21, determining a target synchronous operation corresponding to the state information according to the corresponding relation;
step S22, synchronizing the time of the electronic device with the time of the server by performing the target synchronization operation.
Alternatively, the electronic device may determine the target synchronization operation that should be performed at this time according to the correspondence between the received state information and the state information stored in advance and the synchronization operation.
It is understood that the target synchronization operation refers to an operation of how time synchronization should be performed at this time. In this embodiment, after determining the corresponding target synchronization operation, the electronic device may synchronize the time of the electronic device with the time of the server by executing the target synchronization operation.
According to the time synchronization method provided by the embodiment of the invention, the electronic equipment can determine the target synchronization operation corresponding to the state information sent by the server according to the corresponding relation between the state information stored in the electronic equipment and the synchronization operation, and then the time of the electronic equipment is synchronized with the time of the server by executing the synchronization operation.
In addition, the electronic equipment can execute corresponding synchronous operation according to the actual resource state on the basis of considering the actual resource state of the server, so that time synchronization with the server is realized, the time is not required to be acquired from the client locally, and meanwhile, the requirement of actual service can be met.
Alternatively, in general, the resource status of the server may include a resource abundance status and a resource shortage status, and in detail, the resource status of the server may be classified into a finer class according to the resource shortage level, and may be specifically classified into several classes according to the actual application situation, for example, into a resource abundance, a resource shortage, and so on.
In one possible implementation manner, the resource status of the server may be classified into three types, that is, a resource sufficient status, a first resource shortage status, and a second resource shortage status, based on which, the status information sent by the server may include first status information, second status information, and third status information, and the three status information may respectively represent the different resource shortage degrees, in which case, the corresponding relationship may include a corresponding relationship between the first status information, the second status information, and the third status information and different synchronization operations, and the electronic device may determine the target synchronization operation according to the specific status information and the stored corresponding relationship.
Specifically, the step S21 may be further implemented by:
under the condition that the state information is first state information, determining a target synchronous operation corresponding to the first state information as a first synchronous operation according to the corresponding relation; the first state information characterizes that the current resource state of the server is in a resource abundant state.
In this embodiment, if the electronic device determines that the received state information is the first state information, the electronic device may determine, according to the correspondence, the target synchronization operation corresponding to the first state information as the first synchronization operation.
As will be appreciated, since the first state information characterizes that the current resource state of the server is in a resource-abundant state, the first synchronization operation refers to a time synchronization operation that the server should perform in the resource-abundant state.
Alternatively, the first status information may be a flag parameter, e.g. "idle".
Determining a target synchronous operation corresponding to the second state information as a second synchronous operation according to the corresponding relation under the condition that the state information is the second state information; the second state information characterizes that the current resource state of the server is in a first resource shortage state.
Alternatively, the second status information may be a flag parameter, such as "intense1".
If the state information is third state information, determining a target synchronous operation corresponding to the third state information as a third synchronous operation according to the corresponding relation; the third state information characterizes that the current resource state of the server is in a second resource shortage state, and the resource shortage degree of the second resource shortage state is higher than that of the first resource shortage state.
Alternatively, the third status information may be a flag parameter, such as "intense2".
In this embodiment, if the electronic device determines that the received state information is the second state information, the electronic device may determine, according to the correspondence, the target synchronization operation corresponding to the second state information as the second synchronization operation.
It will be appreciated that, since the second state information characterizes that the current resource state of the server is in the first resource strained state, the second synchronization operation refers to a time synchronization operation that the server should perform in the first resource strained state.
In this embodiment, if the electronic device determines that the received state information is the third state information, the electronic device may determine, according to the correspondence, the target synchronization operation corresponding to the third state information as the third synchronization operation.
It will be appreciated that, since the third state information characterizes that the current resource state of the server is in the second resource strained state, the third synchronization operation refers to a time synchronization operation that the server should perform in the second resource strained state.
In this embodiment, the second resource shortage state has a higher resource shortage degree than the first resource shortage state. For example, if the first resource shortage state is a resource shortage state, the second resource shortage state may be a resource shortage state; if the first resource strained state is a resource strained state, the second resource strained state may be a resource strained state.
Alternatively, the electronic device may implement time synchronization between the electronic device and the server by performing the target synchronization operation after determining the target synchronization operation.
In one possible implementation manner, if the current resource state of the server is a resource abundant state, it is indicated that the electronic device directly obtains time from the server according to the preset time interval at this time and does not affect the performance of the server, so that the electronic device may obtain the time of the server at intervals of the preset time interval under the condition that the target synchronous operation is the first synchronous operation, and set the time of the electronic device according to the time of the server, so that the time of the electronic device is synchronous with the time of the server.
Alternatively, the preset time interval may be set according to the actual application, for example, one minute or one second.
In this embodiment, the electronic device may acquire the time of the server at intervals of a preset time interval when determining that the target synchronization operation is the first synchronization operation, and directly set the time of the electronic device according to the time of the server after acquiring the time of the server.
It will be appreciated that the time of the electronic device may be synchronized with the time of the server by performing the first synchronization operation.
In another possible implementation manner, if the current resource state of the server is a first resource shortage state, that is, the resources are relatively tense at this time, the electronic device may acquire the current time of the server under the condition that the target synchronous operation is the second synchronous operation, and set the current time of the electronic device according to the current time of the server; stopping sending data to the server so that the communication connection between the electronic equipment and the server is in a vacant state; the current time of the electronic device is updated by the timing thread to synchronize the time of the electronic device with the time of the server.
In this embodiment, since the current resources of the server are relatively tense, if the time of the server is acquired once every preset time interval, the performance of the server may be affected, in this case, the electronic device may first acquire the current time of the server and set the current time of the electronic device according to the current time, and then control the electronic device to no longer send data to the server, so that the communication connection between the electronic device and the server is in an idle state, so as to ensure that the resource burden of the server is not aggravated.
Optionally, the idle state refers to a state in which a communication connection between the electronic device and the server is maintained, but no communication is performed between the electronic device and the server.
Optionally, considering that threads such as JavaScript are single-threaded and are easily affected by other tasks, so that timing after long-time running is inaccurate, and therefore the electronic device can perform timing through an autonomous timing thread which can run in parallel with other threads on front-end software arranged on the electronic device.
In one possible implementation, the timing thread may be a Web Worker thread of a browser on the electronic device.
It can be appreciated that the timing thread can run in parallel with other threads, so that the timing thread is not affected by other tasks, and on the basis of the timing thread, accurate time synchronization between the electronic equipment and the server can be realized.
Optionally, in this case, considering that the resource state of the server is already tense, the server may not be able to recover to the resource-abundant state in a short time, so the electronic device may disconnect the communication connection between the electronic device and the server when the duration in which the communication connection between the electronic device and the server is in the idle state reaches the preset duration.
In one possible implementation, the server may continue to acquire its resource status after disconnecting the communication connection with the electronic device, and reestablish the communication connection with the electronic device if the resource is abundant, so that the electronic device performs time synchronization by acquiring the current time of the server if the resource is abundant.
Optionally, if the communication state between the electronic device and the server is in the idle state, and it is determined that the resource state of the server is restored to the resource-rich state, the target synchronization operation may be redetermined to be the first synchronization operation.
In one possible implementation manner, the server may send a restart connection signal to the electronic device when determining that the resource status is a resource abundant status, and the electronic device may exit the idle state with the server after receiving the restart connection signal, resume connection, and reacquire status information sent by the server.
Alternatively, the restart connection signal may be a flag parameter, such as "restart".
In one possible implementation manner, since the server sends the restart connection signal to the electronic device only when determining that its resource status is in the resource-abundant status, the electronic device may determine the current target synchronization operation as the first synchronization operation directly after exiting the idle status and restoring the communication connection with the server, and implement time synchronization with the server by performing the first synchronization operation.
It will be appreciated that at this point the electronic device may shut down the timing thread.
In another possible implementation manner, if the resource of the server is in the second resource shortage state, that is, the resource is extremely intense, then the electronic device may acquire the current time of the server under the condition that the target synchronous operation is the third synchronous operation, and set the current time of the electronic device according to the current time of the server; and disconnecting the communication connection between the electronic equipment and the server, and updating the current time of the electronic equipment through a timing thread so as to synchronize the time of the electronic equipment with the time of the server.
In this embodiment, the electronic device may first obtain the current time of the server to set the current time of the electronic device when the target synchronization operation is the third synchronization operation, and then directly disconnect the communication connection between the electronic device and the server, and update the current time interval of the electronic device through the timing thread, so as to achieve time synchronization between the electronic device and the server.
In one possible implementation, the server may continue to acquire its resource status after disconnecting the communication connection with the electronic device, and reestablish the communication connection with the electronic device if the resource is abundant, so that the electronic device performs time synchronization by acquiring the current time of the server if the resource is abundant.
In addition, in addition to the implementation manner, the server may further store a correspondence between the resource state and the synchronization operation, so that the server may directly acquire the resource state of the server, determine a target synchronization operation corresponding to the current resource state according to the correspondence, and then issue an instruction for executing the target synchronization operation to the electronic device, so that the electronic device realizes time synchronization with the server by executing the instruction.
In order to perform the respective steps of the above embodiments and of the various possible ways, an implementation of a time synchronization device is given below. Further, referring to fig. 4, fig. 4 is a functional block diagram of a time synchronization apparatus according to an embodiment of the present application. It should be noted that, the basic principle and the technical effects of the time synchronization device provided in this embodiment are the same as those of the foregoing embodiment, and for brevity, reference should be made to the corresponding content in the foregoing embodiment. The time synchronization device includes: a receiving module 200, a determining module 210 and a synchronizing module 220.
The receiving module 200 is configured to receive status information sent by a server when the receiving module maintains a communication connection with the server; the state information is used for representing the current resource state of the server;
it is understood that the receiving module 200 may also be used to perform the above step S20;
the determining module 210 is configured to determine a target synchronization operation corresponding to the state information according to the correspondence relationship;
it is understood that the determining module 210 may also be configured to perform the step S21 described above;
the synchronization module 220 is configured to synchronize the time of the electronic device with the time of the server by performing a target synchronization operation.
It is understood that the synchronization module 220 may also be used to perform the step S22 described above.
Optionally, the determining module 210 is further configured to determine, according to the correspondence, that the target synchronization operation corresponding to the first state information is a first synchronization operation if the state information is the first state information; the first state information characterizes that the current resource state of the server is in a resource abundance state; determining a target synchronous operation corresponding to the second state information as a second synchronous operation according to the corresponding relation under the condition that the state information is the second state information; the second state information characterizes that the current resource state of the server is in a first resource shortage state; if the state information is third state information, determining a target synchronous operation corresponding to the third state information as a third synchronous operation according to the corresponding relation; the third state information characterizes that the current resource state of the server is in a second resource shortage state, and the resource shortage degree of the second resource shortage state is higher than that of the first resource shortage state.
Optionally, the synchronization module 220 is further configured to acquire a time of the server at intervals of a preset time interval in a case where the target synchronization operation is the first synchronization operation, and set a time of the electronic device according to the time of the server, so that the time of the electronic device is synchronized with the time of the server.
Optionally, the synchronization module 220 is further configured to obtain a current time of the server and set the current time of the electronic device according to the current time of the server when the target synchronization operation is the second synchronization operation; stopping sending data to the server so that the communication connection between the electronic equipment and the server is in a vacant state; the current time of the electronic device is updated by the timing thread to synchronize the time of the electronic device with the time of the server.
Optionally, the synchronization module 220 is further configured to disconnect the communication connection between the electronic device and the server when a duration of the communication connection between the electronic device and the server in the idle state reaches a preset duration.
Optionally, the synchronization module 220 is further configured to obtain a current time of the server and set the current time of the electronic device according to the current time of the server when the target synchronization operation is the third synchronization operation; and disconnecting the communication connection between the electronic equipment and the server, and updating the current time of the electronic equipment through a timing thread so as to synchronize the time of the electronic equipment with the time of the server.
According to the time synchronization device provided by the embodiment of the application, the state information sent by the server is received through the receiving module under the condition that communication connection is kept between the receiving module and the server; the state information is used for representing the current resource state of the server; determining target synchronous operation corresponding to the state information according to the corresponding relation by a determining module; the synchronization module synchronizes the time of the electronic device with the time of the server by executing the target synchronization operation, so that the corresponding synchronization operation can be executed according to the actual resource state on the basis of considering the actual resource state of the server.
Alternatively, the above modules may be stored in the memory shown in fig. 2 in the form of software or Firmware (Firmware) or cured in an Operating System (OS) of the electronic device, and may be executed by the processor in fig. 2. Meanwhile, data, codes of programs, and the like required to execute the above-described modules may be stored in the memory.
The embodiment of the application also provides a computer readable storage medium, on which a computer program is stored, which when executed by a processor, can implement the time synchronization method provided by the embodiment of the application.
In the several embodiments provided in this application, it should be understood that the disclosed apparatus and method may be implemented in other manners as well. The apparatus embodiments described above are merely illustrative, for example, flow diagrams and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of apparatus, methods and computer program products according to various embodiments of the present application. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams and/or flowchart illustration, and combinations of blocks in the block diagrams and/or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
In addition, the functional modules in the embodiments of the present application may be integrated together to form a single part, or each module may exist alone, or two or more modules may be integrated to form a single part.
The functions, if implemented in the form of software functional modules and sold or used as a stand-alone product, may be stored in a computer-readable storage medium. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art or in a part of the technical solution, in the form of a software product stored in a storage medium, including several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a random access Memory (RAM, random Access Memory), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The foregoing description is only of the preferred embodiments of the present application and is not intended to limit the same, but rather, various modifications and variations may be made by those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principles of the present application should be included in the protection scope of the present application.

Claims (7)

1. A time synchronization method, which is applied to an electronic device, wherein a correspondence between state information and a synchronization operation is stored in the electronic device, the method comprising:
receiving state information sent by a server under the condition of maintaining communication connection with the server; the state information is used for representing the current resource state of the server;
determining a target synchronous operation corresponding to the state information according to the corresponding relation;
synchronizing the time of the electronic device with the time of the server by performing the target synchronization operation;
the synchronizing the time of the electronic device with the time of the server by performing the target synchronization operation includes:
under the condition that the target synchronous operation is a first synchronous operation, acquiring the time of the server at intervals of preset time, and setting the time of the electronic equipment according to the time of the server so as to synchronize the time of the electronic equipment with the time of the server;
under the condition that the target synchronous operation is a second synchronous operation, acquiring the current time of the server, and setting the current time of the electronic equipment according to the current time of the server; stopping sending data to the server so that the communication connection between the electronic equipment and the server is in a vacant state; updating the current time of the electronic equipment through a timing thread so as to synchronize the time of the electronic equipment with the time of the server;
acquiring the current time of the server under the condition that the target synchronous operation is a third synchronous operation, and setting the current time of the electronic equipment according to the current time of the server; and disconnecting the communication connection between the electronic equipment and the server, and updating the current time of the electronic equipment through a timing thread so as to synchronize the time of the electronic equipment with the time of the server.
2. The method according to claim 1, wherein the determining, according to the correspondence relationship, a target synchronization operation corresponding to the state information includes:
determining a target synchronous operation corresponding to the first state information as a first synchronous operation according to the corresponding relation under the condition that the state information is the first state information; the first state information characterizes that the current resource state of the server is in a resource abundant state;
determining a target synchronous operation corresponding to the second state information as a second synchronous operation according to the corresponding relation when the state information is the second state information; the second state information characterizes that the current resource state of the server is in a first resource shortage state;
if the state information is third state information, determining a target synchronous operation corresponding to the third state information as a third synchronous operation according to the corresponding relation; the third state information characterizes that the current resource state of the server is in a second resource shortage state, and the resource shortage degree of the second resource shortage state is higher than that of the first resource shortage state.
3. The method according to claim 1, wherein the method further comprises:
and under the condition that the duration of the communication connection between the electronic equipment and the server in the idle state reaches the preset duration, disconnecting the communication connection between the electronic equipment and the server.
4. A time synchronization apparatus, characterized by being applied to an electronic device in which a correspondence between state information and a synchronization operation is stored, comprising:
the receiving module is used for receiving the state information sent by the server under the condition of keeping communication connection with the server; the state information is used for representing the current resource state of the server;
the determining module is used for determining a target synchronous operation corresponding to the state information according to the corresponding relation;
the synchronization module is used for synchronizing the time of the electronic equipment with the time of the server by executing the target synchronization operation;
the synchronization module is further configured to acquire time of the server at intervals of a preset time interval when the target synchronization operation is a first synchronization operation, and set time of the electronic device according to the time of the server, so that the time of the electronic device is synchronized with the time of the server;
the synchronization module is further configured to obtain a current time of the server and set the current time of the electronic device according to the current time of the server when the target synchronization operation is a second synchronization operation; stopping sending data to the server so that the communication connection between the electronic equipment and the server is in a vacant state; updating the current time of the electronic equipment through a timing thread so as to synchronize the time of the electronic equipment with the time of the server;
the synchronization module is further configured to obtain a current time of the server and set the current time of the electronic device according to the current time of the server when the target synchronization operation is a third synchronization operation; and disconnecting the communication connection between the electronic equipment and the server, and updating the current time of the electronic equipment through a timing thread so as to synchronize the time of the electronic equipment with the time of the server.
5. The apparatus of claim 4, wherein the determining module is further configured to determine, according to the correspondence, that a target synchronization operation corresponding to the first state information is a first synchronization operation, in a case where the state information is the first state information; the first state information characterizes that the current resource state of the server is in a resource abundant state;
the determining module is further configured to determine, according to the correspondence, that a target synchronization operation corresponding to the second state information is a second synchronization operation when the state information is the second state information; the second state information characterizes that the current resource state of the server is in a first resource shortage state;
the determining module is further configured to determine, according to the correspondence, that a target synchronization operation corresponding to the third state information is a third synchronization operation when the state information is the third state information; the third state information characterizes that the current resource state of the server is in a second resource shortage state, and the resource shortage degree of the second resource shortage state is higher than that of the first resource shortage state.
6. An electronic device comprising a processor and a memory, the memory storing a computer program executable by the processor, the processor being executable to implement the method of any one of claims 1-3.
7. A computer readable storage medium, on which a computer program is stored, which computer program, when being executed by a processor, implements the method according to any of claims 1-3.
CN202310314996.2A 2023-03-29 2023-03-29 Time synchronization method, apparatus, electronic device, and computer-readable storage medium Active CN116032949B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310314996.2A CN116032949B (en) 2023-03-29 2023-03-29 Time synchronization method, apparatus, electronic device, and computer-readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310314996.2A CN116032949B (en) 2023-03-29 2023-03-29 Time synchronization method, apparatus, electronic device, and computer-readable storage medium

Publications (2)

Publication Number Publication Date
CN116032949A CN116032949A (en) 2023-04-28
CN116032949B true CN116032949B (en) 2023-06-16

Family

ID=86074400

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310314996.2A Active CN116032949B (en) 2023-03-29 2023-03-29 Time synchronization method, apparatus, electronic device, and computer-readable storage medium

Country Status (1)

Country Link
CN (1) CN116032949B (en)

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106453657A (en) * 2016-12-07 2017-02-22 海信集团有限公司 Status information update method and device of smart home equipment
CN107302580A (en) * 2017-06-30 2017-10-27 北京金山安全软件有限公司 Load balancing method and device, load balancer and storage medium
CN110568984A (en) * 2019-08-22 2019-12-13 北京大米科技有限公司 Online teaching method and device, storage medium and electronic equipment
CN112532334A (en) * 2021-02-18 2021-03-19 北京拓课网络科技有限公司 Time synchronization method and device and electronic equipment
CN114143330A (en) * 2021-11-30 2022-03-04 苏州浪潮智能科技有限公司 Configuration method, device and system of time server
CN115412192A (en) * 2022-08-17 2022-11-29 中国电信股份有限公司 Time synchronization method, device, equipment and medium for network television private network

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9425973B2 (en) * 2006-12-26 2016-08-23 International Business Machines Corporation Resource-based synchronization between endpoints in a web-based real time collaboration
EP2492832B1 (en) * 2011-02-22 2021-08-18 Siemens Healthcare GmbH Optimisation of a software application implemented on a client server system
TWI582607B (en) * 2015-11-02 2017-05-11 廣達電腦股份有限公司 Dynamic resources planning mechanism based on cloud computing and smart device

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106453657A (en) * 2016-12-07 2017-02-22 海信集团有限公司 Status information update method and device of smart home equipment
CN107302580A (en) * 2017-06-30 2017-10-27 北京金山安全软件有限公司 Load balancing method and device, load balancer and storage medium
CN110568984A (en) * 2019-08-22 2019-12-13 北京大米科技有限公司 Online teaching method and device, storage medium and electronic equipment
CN112532334A (en) * 2021-02-18 2021-03-19 北京拓课网络科技有限公司 Time synchronization method and device and electronic equipment
CN114143330A (en) * 2021-11-30 2022-03-04 苏州浪潮智能科技有限公司 Configuration method, device and system of time server
CN115412192A (en) * 2022-08-17 2022-11-29 中国电信股份有限公司 Time synchronization method, device, equipment and medium for network television private network

Non-Patent Citations (3)

* Cited by examiner, † Cited by third party
Title
A Novel Artificial Intelligence Based Timing Synchronization Scheme for Smart Grid Applications;Mohammad Kamrul Hasan, et al.;Wireless Personal Communicaitons(第114期);全文 *
Kenneth Jaldehag ; Carten Rieck ; Per Olof Hedekvist ; Jan Backefeldt.Surveilance of NTP-servers in customer's network.2014 European Frequency and Forum (EFTF).2015,全文. *
NTP授时服务性能监测及状态评估;吴鹏;中国优秀硕士学位论文全文数据库信息科技辑(第08期);全文 *

Also Published As

Publication number Publication date
CN116032949A (en) 2023-04-28

Similar Documents

Publication Publication Date Title
CN109493076B (en) Kafka message unique consumption method, system, server and storage medium
US7890959B2 (en) System and method for message lifetime management
CN109725950B (en) Method, device and storage medium for realizing single-instance operation of client
CN108108296B (en) Cloud testing method, server and client
CN111367698B (en) Application program flash back detection and processing method and device and electronic equipment
US20200210293A1 (en) Application health monitoring and automatic remediation
CN104102570A (en) APP (application) running control method and APP running control device
CN111680015A (en) File resource processing method, device, equipment and medium
CN106162577B (en) A kind of information push method and message pushing equipment
CN116032949B (en) Time synchronization method, apparatus, electronic device, and computer-readable storage medium
CN111427417B (en) Time acquisition method and device and electronic equipment
CN109257396B (en) Distributed lock scheduling method and device
CN110704198B (en) Data operation method, device, storage medium and processor
CN109167830B (en) Method and device for acquiring monitoring data
CN110837431A (en) Service control method, service control device, computer equipment and computer-readable storage medium
CN113360348B (en) Abnormal request processing method and device, electronic equipment and storage medium
CN115421859A (en) Dynamic loading method and device of configuration file, computer equipment and storage medium
CN114385537A (en) Page slot number dynamic allocation method, device, equipment and medium
CN114721876A (en) Data backup method, device and medium
CN114168172A (en) Application program installation method and device, electronic equipment and storage medium
CN107734032B (en) Network connection establishing method and device
CN106445623B (en) System component starting method and device
CN112711517A (en) Server performance monitoring method and device, storage medium and terminal
CN108574622B (en) Instant message processing method and device based on XMPP
CN106027309B (en) The acquisition methods and device of device status information

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
GR01 Patent grant
GR01 Patent grant