A page loading method and device

By creating asynchronous loading of task objects in the main thread and executing them in the child thread, the page lag problem when XML layout file is loaded is solved. The main thread pressure is alleviated through the child thread preloading view, the rendering speed is improved, and the thread pool and ha The use of Clipper table queues is suitable for multitasking concurrency scenarios.

CN113779451BActive Publication Date: 2024-11-15BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010973015.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-09-16
Publication Date
2024-11-15
Estimated Expiration
2040-09-16

AI Technical Summary

Technical Problem

The existing technology will cause the main thread to block when loading XML layout files, especially when the hierarchy is deep or the layout is complex, causing page lag. Due to single-thread loading, the AsyncLayoutInflater class needs to wait in queues for many tasks, which also leads to page lag. Dust.

Method used

Create an asynchronous loading task object through the main thread, including layout file identity and page hash value, and execute the task in the child thread. After loading is completed, put the view into the asynchronous loading task object, and the main thread obtains it from the asynchronous loading task object. The completed view is loaded and rendered, using thread pool and hash table queue to cache data for asynchronous loading.

Benefits of technology

Preloading views through child threads can alleviate the pressure of the main thread, improve view rendering speed, solve page lag problems, and use thread pools and hash table queues to suit more business scenarios.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113779451B_ABST
    Figure CN113779451B_ABST
Patent Text Reader

Abstract

The present invention discloses a page loading method and device, and relates to the field of computer technology. A specific implementation of the method includes: creating an asynchronous loading task object through a main thread; wherein the asynchronous loading task object includes a layout file identifier and a page hash value; executing the asynchronous loading task object through a child thread, and after loading is completed, placing the loaded view into the asynchronous loading task object; obtaining the loaded view from the asynchronous loading task object through the main thread, and rendering the loaded view on the page. This implementation can solve the technical problem of freezing when loading views.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a page loading method and device. Background Art

[0002] In the operating system of the terminal device, XML layout files are often used to display views on the device interface. The process of loading a view by the system is to first read the XML layout file into the memory through IO operations, and then instantiate the object recursively according to the tag and through reflection.

[0003] The current practice is to sequentially load the XML layout file and initialize the view in the main thread (i.e., UI thread); or to asynchronously load the view through the AsyncLayoutInflater class provided by the official interface.

[0004] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:

[0005] If the XML layout file has a deep hierarchy or a complex layout, it will take a long time to load. If the loading operation is performed on the main thread, the main thread operation will be blocked, causing the page to freeze. The AsyncLayoutInflater class is a single-threaded loading class. When there are many loading tasks, you need to wait in line, which will result in the view not being loaded in time, and will also cause the page to freeze. Summary of the invention

[0006] In view of this, an embodiment of the present invention provides a page loading method and device to solve the technical problem of freezing when loading a view.

[0007] To achieve the above object, according to one aspect of an embodiment of the present invention, a page loading method is provided, comprising:

[0008] Through the main thread, create an asynchronous loading task object; wherein the asynchronous loading task object includes a layout file identifier and a page hash value;

[0009] Execute the asynchronous loading task object through the child thread, and after the loading is completed, put the loaded view into the asynchronous loading task object;

[0010] The loaded view is obtained from the asynchronous loading task object through the main thread, and the loaded view is rendered on the page.

[0011] Optionally, create an asynchronous loading task object, including:

[0012] Create an asynchronous loading task object, and put the asynchronous loading task object into a linked list queue;

[0013] The assembly identifier formed by concatenating the layout file identifier and the page hash value is used as a key, and the linked list queue is used as a value and stored in a hash table.

[0014] Optionally, the asynchronous loading task object also includes a view loading status, a loaded view, a callback listener and a synchronization counter;

[0015] Among them, the view loading status includes loading and loading completed, the loaded view is used to put the loaded view of the child thread, the synchronization counter is used to record the number of threads executing the asynchronous loading task object, and the callback listener is used to notify the main thread that the view has been loaded when the count of the synchronization counter is zero.

[0016] Optionally, after placing the loaded view into the asynchronous loading task object, the method further includes:

[0017] The count of the synchronization counter is reduced by one, and the view loading state is modified to loading completed.

[0018] Optionally, obtaining the loaded view from the asynchronous loading task object includes:

[0019] Obtain the linked list queue from the hash table according to the key, and take out the asynchronous loading task object from the linked list queue;

[0020] Determine whether the asynchronous loading task object is empty; if so, load the view through the main thread; if not, obtain the loaded view from the loaded view of the asynchronous loading task object.

[0021] Optionally, obtaining the loaded view from the loaded views of the asynchronous loading task object includes:

[0022] Determine whether the loading completed view of the asynchronous loading task object is empty;

[0023] If so, determining, according to the view loading state of the asynchronous loading task object, to obtain the loaded view from the loaded views of the asynchronous loading task object, or loading the view through the main thread;

[0024] If not, the loaded view is obtained from the loaded views of the asynchronous loading task object.

[0025] Optionally, determining to obtain the loaded view from the loaded views of the asynchronous loading task object according to the view loading state of the asynchronous loading task object, or loading the view through the main thread, includes:

[0026] Determine whether the view loading state of the asynchronous loading task object is loading;

[0027] If so, after waiting for the child thread to finish loading the view, obtain the loaded view from the loaded view of the asynchronous loading task object;

[0028] If not, the view is loaded through the main thread.

[0029] Optionally, after rendering the loaded view on the page, the method further includes:

[0030] When the page is destroyed, the assembly identifier corresponding to the page hash value and the linked list queue corresponding to the assembly identifier are cleared from the hash table according to the page hash value.

[0031] In addition, according to another aspect of an embodiment of the present invention, a page loading device is provided, comprising:

[0032] A creation module is used to create an asynchronous loading task object through a main thread; wherein the asynchronous loading task object includes a layout file identifier and a page hash value;

[0033] The sub-loading module is used to execute the asynchronous loading task object through a sub-thread, and after the loading is completed, put the loaded view into the asynchronous loading task object;

[0034] The main loading module is used to obtain the loaded view from the asynchronous loading task object through the main thread, and render the loaded view on the page.

[0035] Optionally, the creation module is further used to:

[0036] Through the main thread, create an asynchronous loading task object, and put the asynchronous loading task object into a linked list queue;

[0037] The assembly identifier formed by concatenating the layout file identifier and the page hash value is used as a key, and the linked list queue is used as a value and stored in a hash table.

[0038] Optionally, the asynchronous loading task object also includes a view loading status, a loaded view, a callback listener and a synchronization counter;

[0039] Among them, the view loading status includes loading and loading completed, the loaded view is used to put the loaded view of the child thread, the synchronization counter is used to record the number of threads executing the asynchronous loading task object, and the callback listener is used to notify the main thread that the view has been loaded when the count of the synchronization counter is zero.

[0040] Optionally, the sub-loading module is further used for:

[0041] After the loaded view is placed into the asynchronous loading task object through the child thread, the count of the synchronization counter is reduced by one, and the view loading state is modified to loading completed.

[0042] Optionally, the main loading module is further used for:

[0043] Obtain the linked list queue from the hash table according to the key through the main thread, and take out the asynchronous loading task object from the linked list queue;

[0044] Determine whether the asynchronous loading task object is empty; if so, load the view through the main thread; if not, obtain the loaded view from the loaded view of the asynchronous loading task object.

[0045] Optionally, the main loading module is further used for:

[0046] Determine, through the main thread, whether the loading completed view of the asynchronous loading task object is empty;

[0047] If so, determining, according to the view loading state of the asynchronous loading task object, to obtain the loaded view from the loaded views of the asynchronous loading task object, or loading the view through the main thread;

[0048] If not, the loaded view is obtained from the loaded views of the asynchronous loading task object.

[0049] Optionally, the main loading module is further used for:

[0050] Determine, through the main thread, whether the view loading state of the asynchronous loading task object is loading;

[0051] If so, after waiting for the child thread to finish loading the view, obtain the loaded view from the loaded view of the asynchronous loading task object;

[0052] If not, the view is loaded through the main thread.

[0053] Optionally, the main loading module is further used for:

[0054] After rendering the loaded view on the page through the main thread, when the page is destroyed, the assembly identifier corresponding to the page hash value and the linked list queue corresponding to the assembly identifier are cleared from the hash table according to the page hash value.

[0055] According to another aspect of an embodiment of the present invention, there is further provided an electronic device, including:

[0056] one or more processors;

[0057] a storage device for storing one or more programs,

[0058] When the one or more programs are executed by the one or more processors, the one or more processors implement the method described in any one of the above embodiments.

[0059] According to another aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored. When the program is executed by a processor, the method described in any one of the above embodiments is implemented.

[0060] One embodiment of the above invention has the following advantages or beneficial effects: because it adopts the technical means of creating an asynchronous loading task object, executing the asynchronous loading task object through a child thread, and placing the loaded view into the asynchronous loading task object after loading is completed, it overcomes the technical problem of freezing when loading views in the prior art. The embodiment of the present invention preloads the view through a child thread, relieves the pressure of the main thread, improves the view rendering speed, and solves the problem of page freezing. Moreover, the embodiment of the present invention uses a thread pool instead of a single thread to handle multi-task concurrency, uses a hash table and a linked list queue to cache data, and realizes access separation, which can be applied to more business scenarios.

[0061] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0062] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0063] Figure 1 is a schematic diagram of the main process of the page loading method according to an embodiment of the present invention;

[0064] Figure 2 is a schematic diagram of accessing data through a hash table according to an embodiment of the present invention;

[0065] Figure 3 is a schematic diagram of the main process of a page loading method according to a reference embodiment of the present invention;

[0066] Figure 4 is a schematic diagram of the main process of a page loading method according to another reference embodiment of the present invention;

[0067] Figure 5 is a schematic diagram of main modules of a page loading device according to an embodiment of the present invention;

[0068] Figure 6 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0069] Figure 7 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0070] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0071] Figure 1 Schematic diagram of the main process of the page loading method according to an embodiment of the present invention. As an embodiment of the present invention, Figure 1 As shown, the page loading method may include:

[0072] Step 101, creating an asynchronous loading task object through the main thread, wherein the asynchronous loading task object includes a layout file identifier and a page hash value.

[0073] The embodiment of the present invention solves the jamming problem by asynchronous loading, so it is necessary to first create an asynchronous loading task object (AsyncInflaterItem) through the main thread so that the child thread can execute the asynchronous loading task object. The asynchronous loading task object includes a layout file identifier and a page hash value. It should be pointed out that the layout file can be an XML layout file, the layout file identifier (layoutID) is globally unique, and the page hash value (page hashcode) is also globally unique. Loading a page (activity) requires at least one layout file, so a page corresponds to at least one layout file identifier. A layout file corresponds to a view (view), that is, a layout file can load a view.

[0074] Optionally, creating an asynchronous loading task object includes: creating an asynchronous loading task object, placing the asynchronous loading task object into a linked list queue; using the assembly identifier formed by concatenating the layout file identifier and the page hash value as a key and the linked list queue as a value, storing the assembly identifier in a hash table. Figure 2As shown, after the main thread creates the asynchronous loading task object, it puts the asynchronous loading task object into a linked list queue (LinkedBlockingQueue), and uses layoutID+page hashcode as the key and LinkedBlockingQueue as the value. The key-value is stored in a hash table (HashMap). Therefore, the asynchronous loading task objects corresponding to the same key can be put into the same linked list queue, so that the child thread executes each asynchronous loading task object in the linked list queue in turn.

[0075] Optionally, the embodiment of the present invention uses soft references to package the linked list queue, so that GC can reclaim memory when the system memory is too low. GC: Garbage Collection, the GC provided by Java can automatically monitor whether the object exceeds the scope to achieve the purpose of automatically reclaiming memory.

[0076] Optionally, the asynchronous loading task object also includes a view loading status, a loaded view, a callback listener and a synchronization counter; wherein the view loading status includes loading in progress and loaded, the loaded view is used to place the loaded view of the child thread, the synchronization counter is used to record the number of threads executing the asynchronous loading task object, and the callback listener is used to notify the main thread that the view has been loaded when the count of the synchronization counter is zero. In an embodiment of the present invention, in order to facilitate monitoring of the loading status of the view, the asynchronous loading task object may further include a view loading status, a callback listener and a synchronization counter (countDownLatch). Since the present application executes the asynchronous loading task object by a single thread, the count of the synchronization counter is 1. When the asynchronous loading task is completed, the count of the synchronization counter is subtracted by 1, that is, zero.

[0077] After the main thread creates the asynchronous loading task object, the view loading status in the created asynchronous loading task object can be loading. Because after the main thread creates the asynchronous loading task object, the child thread will immediately start executing the asynchronous loading task object. Therefore, in order to reduce the number of status modifications, the view loading status can be set to loading when it is created.

[0078] Step 102, execute the asynchronous loading task object through the child thread, and after the loading is completed, put the loaded view into the asynchronous loading task object.

[0079] The embodiment of the present invention uses a thread pool to solve the single-thread queuing waiting problem, so before step 102, a thread pool needs to be created, and each sub-thread in the thread pool is used to execute the asynchronous loading task object. Optionally, there are 2 resident sub-threads (i.e., core threads) in the thread pool, and the maximum number of sub-threads in the thread pool is 3, which can avoid performance consumption due to excessive overhead.

[0080] In step 102, if Figure 2 As shown, the child thread obtains the corresponding value from the HashMap according to the key, that is, the LinkedBlockingQueue, and the HashMap still retains the LinkedBlockingQueue. Then the child thread takes out the asynchronous loading task objects from the LinkedBlockingQueue in turn and executes the asynchronous loading task objects. After each asynchronous loading task object is executed, the LinkedBlockingQueue no longer retains the asynchronous loading task object.

[0081] Optionally, after placing the loaded view into the asynchronous loading task object, it also includes: subtracting one from the count of the synchronization counter and changing the view loading state to loading completed. After loading is completed, the child thread places the loaded view into the asynchronous loading task object of the LinkedBlockingQueue of the HashMap, subtracts 1 from the count of the synchronization counter, that is, zero, and then changes the view loading state to loading completed. Furthermore, when the count of the synchronization counter is zero, the callback listener notifies the main thread that the view has been loaded.

[0082] Step 103: Obtain the loaded view from the asynchronous loading task object through the main thread, and render the loaded view on the page.

[0083] Since the child thread puts the loaded view into the asynchronous loading task object, the main thread can obtain the loaded view from the asynchronous loading task object and then render the view on the page.

[0084] Optionally, obtaining the loaded view from the asynchronous loading task object includes: obtaining the linked list queue from the hash table according to the key, and taking out the asynchronous loading task object from the linked list queue; determining whether the asynchronous loading task object is empty; if so, loading the view through the main thread; if not, obtaining the loaded view from the loaded view of the asynchronous loading task object. If the asynchronous loading task object obtained from the linked list queue is empty, indicating that the asynchronous loading has failed, the view loading is implemented by following the fallback logic (i.e., loading the view through the main thread); if the asynchronous loading task object is obtained from the linked list queue, indicating that the asynchronous loading is successful, the loaded view is directly obtained from the loaded view of the asynchronous loading task object.

[0085] Optionally, obtaining the loaded view from the loaded view of the asynchronous loading task object includes: determining whether the loaded view of the asynchronous loading task object is empty; if so, determining whether to obtain the loaded view from the loaded view of the asynchronous loading task object according to the view loading status of the asynchronous loading task object, or loading the view through the main thread; if not, obtaining the loaded view from the loaded view of the asynchronous loading task object. Even if the asynchronous loading task object is obtained from the linked list queue, it cannot be guaranteed that the loaded view is placed in the asynchronous loading task object. Therefore, it is necessary to further determine whether the loaded view of the asynchronous loading task object is empty. If it is empty, determine whether to follow the fallback logic according to the view loading status; if it is not empty and the asynchronous loading is successful, then directly obtain the loaded view from the loaded view of the asynchronous loading task object.

[0086] Optionally, according to the view loading status of the asynchronous loading task object, it is determined whether to obtain the loaded view from the loaded view of the asynchronous loading task object, or the view is loaded through the main thread, including: judging whether the view loading status of the asynchronous loading task object is loading; if so, waiting for the child thread to finish loading the view, and obtaining the loaded view from the loaded view of the asynchronous loading task object; if not, loading the view through the main thread. If the view loading status is loading, the countDownLatch.wait() method in the asynchronous loading task object is called, and when the count of the synchronization counter is zero, it is judged again whether the loaded view in the asynchronous loading task object at this time is empty. If it is not empty, it means that the asynchronous loading is successful, and the loaded view is directly obtained from the loaded view of the asynchronous loading task object. If it is still empty, the fallback logic is used.

[0087] Optionally, after rendering the loaded view on the page, the method further includes: when the page is destroyed, according to the page hash value, clearing the assembly identifier corresponding to the page hash value and the linked list queue corresponding to the assembly identifier from the hash table. Figure 2 As shown in the figure, taking the page (activity) as the dimension, when the page is destroyed, the main thread will clear the key containing the hashcode of the page and its corresponding value from the HashMap. Since the value uses soft references, when the system memory is too low, the GC will actively recycle these soft references. If there are still unused views cached in the LinkedBlockingQueue, clearing them will not affect normal use.

[0088] In order to make Factory2 compatible with controls such as AppCompatTextView, you can customize LayoutInflater and determine whether the AppCompatDelegate type of the context is Factory2. If so, manually set Factory2 to make it compatible with controls such as AppCompatTextView.

[0089] According to the various embodiments described above, it can be seen that the embodiment of the present invention solves the technical problem of jamming when loading views in the prior art by creating an asynchronous loading task object, executing the asynchronous loading task object through a child thread, and placing the loaded view into the asynchronous loading task object after loading is completed. The embodiment of the present invention preloads the view through a child thread, relieves the pressure of the main thread, improves the view rendering speed, and solves the page jamming problem. Moreover, the embodiment of the present invention uses a thread pool instead of a single thread to handle multi-task concurrency, uses a hash table and a linked list queue to cache data, and realizes access separation, which can be applied to more business scenarios.

[0090] Figure 3 Schematic diagram of the main process of a page loading method according to a reference embodiment of the present invention. As an embodiment of the present invention, Figure 3 As shown, the page loading method may include:

[0091] Step 301, create an asynchronous loading task object through the main thread, and put the asynchronous loading task object into a linked list queue.

[0092] The main thread creates an asynchronous loading task object and puts the asynchronous loading task object into the linked list queue. The asynchronous loading task object includes a layout file identifier, a page hash value, a view loading status, a loaded view, a callback listener, and a synchronization counter. The view loading status includes loading and loading completed. The loaded view is used to put the loaded view of the child thread. The synchronization counter is used to record the number of threads executing the asynchronous loading task object. The callback listener is used to notify the main thread that the view has been loaded when the count of the synchronization counter is zero.

[0093] Step 302: Through the main thread, the assembly identifier formed by concatenating the layout file identifier and the page hash value is used as a key, and the linked list queue is used as a value to store it in a hash table.

[0094] Step 303: execute the asynchronous loading task object through a child thread.

[0095] Before step 303, a thread pool needs to be created, and each sub-thread in the thread pool is used to execute the asynchronous loading task object. Optionally, there are 2 resident sub-threads (i.e., core threads) in the thread pool, and the maximum number of sub-threads in the thread pool is 3, which can avoid performance consumption due to excessive overhead.

[0096] The embodiment of the present invention executes the asynchronous loading task object through the child thread in the thread pool. The child thread obtains the corresponding value, that is, LinkedBlockingQueue, from the HashMap according to the key, and the HashMap still retains the LinkedBlockingQueue. Then the child thread sequentially takes out the asynchronous loading task object from the LinkedBlockingQueue and executes the asynchronous loading task object. After each asynchronous loading task object is executed, the LinkedBlockingQueue no longer retains the asynchronous loading task object.

[0097] Step 304: After loading is completed, the loaded view is placed in the asynchronous loading task object through the child thread, the count of the synchronization counter is reduced by one, and the view loading state is modified to loading completed.

[0098] Step 305: Obtain the loaded view from the asynchronous loading task object through the main thread.

[0099] Step 306: Render the loaded view on the page through the main thread.

[0100] Since the child thread puts the loaded view into the asynchronous loading task object, the main thread can obtain the loaded view from the asynchronous loading task object and then render the view on the page.

[0101] Step 307, when the page is destroyed, the assembly identifier corresponding to the page hash value and the linked list queue corresponding to the assembly identifier are cleared from the hash table through the main thread according to the page hash value.

[0102] In addition, the specific implementation content of the page loading method in a reference embodiment of the present invention has been described in detail in the above-mentioned page loading method, so the repeated content will not be described again here.

[0103] Figure 4 Schematic diagram of the main process of a page loading method according to another reference embodiment of the present invention. As another embodiment of the present invention, Figure 4 As shown, the step of the main thread obtaining the loaded view from the asynchronous loading task object may specifically include the following steps:

[0104] Step 401, obtain LinkedBlockingQueue from HashMap according to key, and take out AsyncInflaterItem from LinkedBlockingQueue.

[0105] Step 402, determine whether AsyncInflaterItem is empty; if so, execute step 407; if not, execute step 403.

[0106] Step 403 , determine whether the loaded view of AsyncInflaterItem is empty; if so, execute step 404 ; if not, execute step 408 .

[0107] Step 404 , determine whether the view loading status of AsyncInflaterItem is loading; if so, execute step 405 ; if not, execute step 407 .

[0108] Step 405, call the countDownLatch.wait() method in AsyncInflaterItem.

[0109] Step 406, when the count of countDownLatch is zero, determine whether the loaded view of AsyncInflaterItem is empty; if so, execute step 407; if not, execute step 408.

[0110] Step 407, loading the view through the main thread.

[0111] Step 408, obtaining the loaded view from the loaded views of AsyncInflaterItem.

[0112] In addition, the specific implementation content of the page loading method in another reference embodiment of the present invention has been described in detail in the above-mentioned page loading method, so the repeated content will not be described again here.

[0113] Figure 5 is a schematic diagram of the main modules of the page loading device according to an embodiment of the present invention. Figure 5 As shown, the page loading device 500 includes a creation module 501, a sub-loading module 502 and a main loading module 503; the creation module 501 is used to create an asynchronous loading task object through a main thread; wherein the asynchronous loading task object includes a layout file identifier and a page hash value; the sub-loading module 502 is used to execute the asynchronous loading task object through a sub-thread, and after loading is completed, put the loaded view into the asynchronous loading task object; the main loading module 503 is used to obtain the loaded view from the asynchronous loading task object through the main thread, and render the loaded view on the page.

[0114] Optionally, the creation module 501 is further used for:

[0115] Through the main thread, create an asynchronous loading task object, and put the asynchronous loading task object into a linked list queue;

[0116] The assembly identifier formed by concatenating the layout file identifier and the page hash value is used as a key, and the linked list queue is used as a value and stored in a hash table.

[0117] Optionally, the asynchronous loading task object also includes a view loading status, a loaded view, a callback listener and a synchronization counter;

[0118] Among them, the view loading status includes loading and loading completed, the loaded view is used to put the loaded view of the child thread, the synchronization counter is used to record the number of threads executing the asynchronous loading task object, and the callback listener is used to notify the main thread that the view has been loaded when the count of the synchronization counter is zero.

[0119] Optionally, the sub-loading module 502 is further used for:

[0120] After the loaded view is placed into the asynchronous loading task object through the child thread, the count of the synchronization counter is reduced by one, and the view loading state is modified to loading completed.

[0121] Optionally, the main loading module 503 is further used for:

[0122] Obtain the linked list queue from the hash table according to the key through the main thread, and take out the asynchronous loading task object from the linked list queue;

[0123] Determine whether the asynchronous loading task object is empty; if so, load the view through the main thread; if not, obtain the loaded view from the loaded view of the asynchronous loading task object.

[0124] Optionally, the main loading module 503 is further used for:

[0125] Determine, through the main thread, whether the loading completed view of the asynchronous loading task object is empty;

[0126] If so, determining, according to the view loading state of the asynchronous loading task object, to obtain the loaded view from the loaded views of the asynchronous loading task object, or loading the view through the main thread;

[0127] If not, the loaded view is obtained from the loaded views of the asynchronous loading task object.

[0128] Optionally, the main loading module 503 is further used for:

[0129] Determine, through the main thread, whether the view loading state of the asynchronous loading task object is loading;

[0130] If so, after waiting for the child thread to finish loading the view, obtain the loaded view from the loaded view of the asynchronous loading task object;

[0131] If not, the view is loaded through the main thread.

[0132] Optionally, the main loading module 503 is further used for:

[0133] After rendering the loaded view on the page through the main thread, when the page is destroyed, the assembly identifier corresponding to the page hash value and the linked list queue corresponding to the assembly identifier are cleared from the hash table according to the page hash value.

[0134] According to the various embodiments described above, it can be seen that the embodiment of the present invention solves the technical problem of jamming when loading views in the prior art by creating an asynchronous loading task object, executing the asynchronous loading task object through a child thread, and placing the loaded view into the asynchronous loading task object after loading is completed. The embodiment of the present invention preloads the view through a child thread, relieves the pressure of the main thread, improves the view rendering speed, and solves the page jamming problem. Moreover, the embodiment of the present invention uses a thread pool instead of a single thread to handle multi-task concurrency, uses a hash table and a linked list queue to cache data, and realizes access separation, which can be applied to more business scenarios.

[0135] It should be noted that the specific implementation content of the page loading device of the present invention has been described in detail in the above-mentioned page loading method, so the repeated content will not be described again here.

[0136] Figure 6 An exemplary system architecture 600 to which the page loading method or the page loading apparatus according to the embodiment of the present invention can be applied is shown.

[0137] like Figure 6 As shown, system architecture 600 may include terminal devices 601, 602, 603, network 604 and server 605. Network 604 is used to provide a medium for communication links between terminal devices 601, 602, 603 and server 605. Network 604 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0138] Users can use terminal devices 601, 602, and 603 to interact with server 605 through network 604 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 601, 602, and 603, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).

[0139] The terminal devices 601 , 602 , and 603 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, and desktop computers, etc.

[0140] The server 605 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 601, 602, and 603. The backend management server may analyze and process the received data such as the item information query request, and feed back the processing results (such as target push information, item information - only an example) to the terminal device.

[0141] It should be noted that the page loading method provided in the embodiment of the present invention can be executed by the terminal devices 601 , 602 , and 603 , and accordingly, the page loading device can be set in the terminal devices 601 , 602 , and 603 .

[0142] It should be understood that Figure 6 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0143] Reference below Figure 7 , which shows a schematic diagram of the structure of a computer system 700 of a terminal device suitable for implementing an embodiment of the present invention. Figure 7 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0144] like Figure 7 As shown, the computer system 700 includes a central processing unit (CPU) 701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 702 or a program loaded from a storage part 708 into a random access memory (RAM) 703. In the RAM 703, various programs and data required for the operation of the system 700 are also stored. The CPU 701, the ROM 702, and the RAM 703 are connected to each other via a bus 704. An input / output (I / O) interface 705 is also connected to the bus 704.

[0145] The following components are connected to the I / O interface 705: an input section 706 including a keyboard, a mouse, etc.; an output section 707 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 708 including a hard disk, etc.; and a communication section 709 including a network interface card such as a LAN card, a modem, etc. The communication section 709 performs communication processing via a network such as the Internet. A drive 710 is also connected to the I / O interface 705 as needed. A removable medium 711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 710 as needed, so that a computer program read therefrom is installed into the storage section 708 as needed.

[0146] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 709, and / or installed from the removable medium 711. When the computer program is executed by the central processing unit (CPU) 701, the above-mentioned functions defined in the system of the present invention are executed.

[0147] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0148] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0149] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor, for example, it may be described as follows: a processor includes a creation module, a sub-loading module and a main loading module, wherein the names of these modules do not constitute a limitation on the modules themselves in some cases.

[0150] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device implements the following method: through the main thread, create an asynchronous loading task object; wherein the asynchronous loading task object includes a layout file identifier and a page hash value; through the child thread, execute the asynchronous loading task object, and after loading is completed, put the loaded view into the asynchronous loading task object; through the main thread, obtain the loaded view from the asynchronous loading task object, and render the loaded view on the page.

[0151] According to the technical solution of the embodiment of the present invention, the technical problem of freezing when loading views in the prior art is overcome because of the technical means of creating an asynchronous loading task object, executing the asynchronous loading task object through a child thread, and placing the loaded view into the asynchronous loading task object after loading is completed. The embodiment of the present invention preloads the view through a child thread, relieves the pressure of the main thread, improves the view rendering speed, and solves the problem of page freezing. Moreover, the embodiment of the present invention uses a thread pool instead of a single thread to handle multi-task concurrency, uses a hash table and a linked list queue to cache data, and realizes access separation, which can be applied to more business scenarios.

[0152] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A page loading method, characterized in that: include: Through the main thread, create an asynchronous loading task object; wherein the asynchronous loading task object includes a layout file identifier and a page hash value; Execute the asynchronous loading task object through the child thread, and after the loading is completed, put the loaded view into the asynchronous loading task object; Obtaining the loaded view from the asynchronous loading task object through the main thread, and rendering the loaded view on the page; Create an asynchronous loading task object, including: Create an asynchronous loading task object, and put the asynchronous loading task object into a linked list queue; Using the assembly identifier formed by concatenating the layout file identifier and the page hash value as a key and the linked list queue as a value, the assembly identifier is stored in a hash table; The asynchronous loading task object also includes the view loading status, the loaded view, the callback listener and the synchronization counter; Among them, the view loading status includes loading and loading completed, the loaded view is used to put the loaded view of the child thread, the synchronization counter is used to record the number of threads executing the asynchronous loading task object, and the callback listener is used to notify the main thread that the view has been loaded when the count of the synchronization counter is zero.

2. The method according to claim 1, characterized in that After placing the loaded view into the asynchronous loading task object, it also includes: The count of the synchronization counter is reduced by one, and the view loading state is modified to loading completed.

3. The method according to claim 1, characterized in that Obtaining the loaded view from the asynchronous loading task object includes: Obtain the linked list queue from the hash table according to the key, and take out the asynchronous loading task object from the linked list queue; Determine whether the asynchronous loading task object is empty; if so, load the view through the main thread; if not, obtain the loaded view from the loaded view of the asynchronous loading task object.

4. The method according to claim 3, characterized in that Obtaining the loaded view from the loaded view of the asynchronous loading task object, including: Determine whether the loading completed view of the asynchronous loading task object is empty; If so, determining, according to the view loading state of the asynchronous loading task object, to obtain the loaded view from the loaded views of the asynchronous loading task object, or loading the view through the main thread; If not, the loaded view is obtained from the loaded views of the asynchronous loading task object.

5. The method according to claim 4, characterized in that Determining, according to the view loading state of the asynchronous loading task object, to obtain a loaded view from the loaded view of the asynchronous loading task object, or loading the view through the main thread, includes: Determine whether the view loading state of the asynchronous loading task object is loading; If so, after waiting for the child thread to finish loading the view, obtain the loaded view from the loaded view of the asynchronous loading task object; If not, the view is loaded through the main thread.

6. The method according to claim 1, characterized in that After rendering the loaded view on the page, the method further includes: When the page is destroyed, the assembly identifier corresponding to the page hash value and the linked list queue corresponding to the assembly identifier are cleared from the hash table according to the page hash value.

7. A page loading device, characterized in that: include: A creation module is used to create an asynchronous loading task object through a main thread; wherein the asynchronous loading task object includes a layout file identifier and a page hash value; The sub-loading module is used to execute the asynchronous loading task object through a sub-thread, and after the loading is completed, put the loaded view into the asynchronous loading task object; A main loading module, used to obtain the loaded view from the asynchronous loading task object through the main thread, and render the loaded view on the page; The creation module is also used to: Through the main thread, create an asynchronous loading task object, and put the asynchronous loading task object into a linked list queue; Using the assembly identifier formed by concatenating the layout file identifier and the page hash value as a key and the linked list queue as a value, the assembly identifier is stored in a hash table; The asynchronous loading task object also includes the view loading status, the loaded view, the callback listener and the synchronization counter; Among them, the view loading status includes loading and loading completed, the loaded view is used to put the loaded view of the child thread, the synchronization counter is used to record the number of threads executing the asynchronous loading task object, and the callback listener is used to notify the main thread that the view has been loaded when the count of the synchronization counter is zero.

8. An electronic device, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 6.

9. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 6 is implemented.