CN104881320A - Scalable text generation method - Google Patents
Scalable text generation method Download PDFInfo
- Publication number
- CN104881320A CN104881320A CN201510267434.2A CN201510267434A CN104881320A CN 104881320 A CN104881320 A CN 104881320A CN 201510267434 A CN201510267434 A CN 201510267434A CN 104881320 A CN104881320 A CN 104881320A
- Authority
- CN
- China
- Prior art keywords
- rendering
- thread
- template
- tasks
- text
- 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.)
- Granted
Links
Landscapes
- Document Processing Apparatus (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
本发明提供一种可伸缩的生成文本的方法,能够更快的渲染文本文件,更高效的利用服务器的CPU资源。该方法包括:将整个模板文件分解成多个子模板文件;生成渲染任务列表,所述渲染任务列表中包含多个渲染任务,所述多个渲染任务用于关联该多个渲染任务对应的所述多个子模板文件,并且实现渲染前准备数据的逻辑;将所述多个渲染任务进行多线程渲染;以及将所述多个渲染任务的渲染结果拼接以生成文本。采用本发明的技术方案,降低了模板文件的开发维护成本,数据准备更为高效,服务器的CPU资源利用更为合理。
The invention provides a scalable text generation method, which can render text files faster and utilize CPU resources of a server more efficiently. The method includes: decomposing the entire template file into multiple sub-template files; generating a rendering task list, the rendering task list includes multiple rendering tasks, and the multiple rendering tasks are used to associate the multiple rendering tasks corresponding to the multiple sub-template files, and implement the logic of preparing data before rendering; perform multi-thread rendering on the multiple rendering tasks; and splicing the rendering results of the multiple rendering tasks to generate text. By adopting the technical solution of the invention, the development and maintenance cost of the template file is reduced, the data preparation is more efficient, and the CPU resource utilization of the server is more reasonable.
Description
技术领域technical field
本发明涉及计算机网络技术领域,特别地涉及一种可伸缩的生成文本的方法。The invention relates to the technical field of computer networks, in particular to a scalable text generation method.
背景技术Background technique
文本文件是一类重要的计算机文件,由于结构简单,文本文件被广泛用于记录信息。为了提升开发效率,使代码可以重用,在生成文本时引入了模板引擎(template engine),使用模板引擎后就可以达到逻辑分离的功能,使程序应用逻辑和页面显示逻辑分开,能让程序开发者专注于资料的控制或是功能的达成;而视觉设计师则可专注于页面排版,让页面看起来更具有专业感。Text files are an important class of computer files. Due to their simple structure, text files are widely used to record information. In order to improve the development efficiency and make the code reusable, a template engine (template engine) is introduced when generating text. After using the template engine, the function of logic separation can be achieved, so that the program application logic and page display logic are separated, allowing program developers Focus on the control of data or the achievement of functions; while visual designers can focus on page layout to make the page look more professional.
以用Java语言生成一种常见的文本——HTML页面为例。在用Java语言进行HTML页面生成时,通常情况下,开发人员不会直接编写整个HTML页面,而是按照一定的逻辑,将一个HTML页面分块成很多个HTML模板,再用基于Java的模板引擎最终生成整个HTML页面。Take the Java language to generate a common text—HTML page as an example. When using the Java language to generate HTML pages, under normal circumstances, developers will not directly write the entire HTML page, but divide an HTML page into many HTML templates according to certain logic, and then use the Java-based template engine Eventually the entire HTML page is generated.
通常使用的基于Java的模板引擎有Velocity,FreeMarker等。例如Velocity,它允许任何人仅仅使用简单的模板语言(templatelanguage)来引用由Java代码定义的对象,并且将Java对象和模板本身以渲染的方式,最终生成一个HTML片段。当Velocity应用于Web页面开发时,页面设计人员可以只关注页面的显示效果,而由Java程序开发人员关注业务逻辑编码。Velocity将Java代码从web页面中分离出来,这样为web站点的长期维护也提供了便利。Commonly used Java-based template engines include Velocity, FreeMarker, etc. For example, Velocity, which allows anyone to use a simple template language (template language) to refer to objects defined by Java code, and render Java objects and templates themselves, and finally generate an HTML fragment. When Velocity is applied to Web page development, page designers can only focus on the display effect of the page, while Java program developers focus on business logic coding. Velocity separates Java code from web pages, which also facilitates long-term maintenance of web sites.
当需要用Velocity渲染一个HTML页面时,现有技术通常包含以下几个步骤:When it is necessary to render an HTML page with Velocity, the prior art usually includes the following steps:
1.将整个HTML页面中的变量按照Velocity语法替换成Java对象的引用以生成Velocity模板文件;1. Replace the variables in the entire HTML page with Java object references according to Velocity syntax to generate Velocity template files;
2.通过Java后台逻辑单线程依次组装Velocity模板文件所需要的数据;2. The data required by the Velocity template file is assembled sequentially through the Java background logic single thread;
3.将Velocity模板文件和Java后台逻辑组装的数据作为Velocity中渲染方法的输入,执行Velocity中的渲染(render)方法,最终得到渲染方法的输出生成完整的HTML页面。3. Use the Velocity template file and the data assembled by the Java background logic as the input of the rendering method in Velocity, execute the rendering (render) method in Velocity, and finally obtain the output of the rendering method to generate a complete HTML page.
由此可见,现有基于Java的生成文本的方法有以下几个缺点:It can be seen that the existing Java-based method for generating text has the following disadvantages:
1.如果模板文件内容很多,会导致整个模板文件很长,增加开发人员的开发维护成本。1. If the template file has a lot of content, the entire template file will be very long, which will increase the development and maintenance costs of developers.
2.Java后台准备数据的过程为单线程,如果模板文件需要的数据很多,Java后台组装数据的逻辑需要很长时间才能将所有数据准备好,之后再调用渲染方法,因此页面生成时间很长。2. The process of preparing data in the Java background is single-threaded. If the template file requires a lot of data, the logic of assembling data in the Java background will take a long time to prepare all the data, and then call the rendering method, so the page generation time is very long.
3.如果服务器CPU利用率较低时,渲染文本的过程还是必须遵循依次准备数据再渲染的过程,无法更高效的利用服务器的CPU资源。3. If the CPU utilization rate of the server is low, the process of rendering text must still follow the process of preparing data and then rendering in sequence, and the CPU resources of the server cannot be used more efficiently.
发明内容Contents of the invention
有鉴于此,本发明提供一种可伸缩的生成文本的方法,具体方案为:将一个大模板文件分解成多个子模板文件,并编写渲染任务关联对应的模板文件和数据,然后将渲染任务发给线程池进行多线程渲染,全部渲染任务结束后将渲染结果进行拼接以生成完整的文本。该方法能够更快的渲染文本文件,可以在服务器CPU利用率较低时,尽可能多的利用服务器的CPU资源,加快文本的渲染,并且在服务器利用率达到一定程度时自动保护服务器CPU资源,延长服务器在接收到大量渲染请求下的工作时间。In view of this, the present invention provides a scalable text generation method. The specific solution is: decompose a large template file into multiple sub-template files, write the corresponding template file and data associated with the rendering task, and then send the rendering task to Multi-threaded rendering is performed for the thread pool, and after all rendering tasks are completed, the rendering results are spliced to generate a complete text. This method can render text files faster, can use as much CPU resources of the server as possible when the CPU utilization of the server is low, speeds up the rendering of text, and automatically protects the CPU resources of the server when the utilization of the server reaches a certain level, Extend the working time of the server when receiving a large number of rendering requests.
为实现上述目的,本发明提供了一种可伸缩的生成文本的方法。To achieve the above purpose, the present invention provides a scalable text generation method.
本发明的一种可伸缩的生成文本的方法包括:将整个模板文件分解成多个子模板文件;生成渲染任务列表,所述渲染任务列表中包含多个渲染任务,所述多个渲染任务用于关联该多个渲染任务对应的所述多个子模板文件,并且实现渲染前准备数据的逻辑;将所述多个渲染任务进行多线程渲染;以及将所述多个渲染任务的渲染结果拼接以生成文本。A scalable text generation method of the present invention includes: decomposing the entire template file into multiple sub-template files; generating a rendering task list, the rendering task list includes multiple rendering tasks, and the multiple rendering tasks are used for Associating the plurality of sub-template files corresponding to the plurality of rendering tasks, and implementing the logic of preparing data before rendering; performing multi-threaded rendering of the plurality of rendering tasks; and splicing the rendering results of the plurality of rendering tasks to generate text.
可选地,将整个模板文件分解成多个子模板文件包括:将文本中的变量按照模板引擎的语法替换成Java对象的引用生成整个模板文件;以及分解成多个子模板文件。Optionally, decomposing the entire template file into multiple sub-template files includes: replacing variables in the text with Java object references according to template engine syntax to generate the entire template file; and decomposing into multiple sub-template files.
可选地,将整个模板文件分解成多个子模板文件包括:将文本中的变量分解成多个小组;以及将每个小组的变量按照模板引擎的语法替换成Java对象的引用生成子模板文件。Optionally, decomposing the entire template file into multiple sub-template files includes: decomposing the variables in the text into multiple sub-template files; and replacing the variables of each sub-template file with Java object references according to the syntax of the template engine to generate sub-template files.
可选地,将整个模板文件分解成多个子模板文件包括:将整个模板文件,按页面结构和所估计的数据准备所需要的时间的长短,分解成多个子模板文件。Optionally, decomposing the entire template file into multiple sub-template files includes: decomposing the entire template file into multiple sub-template files according to the page structure and estimated time required for data preparation.
可选地,所述多个渲染任务包含与所述多个渲染任务相对应的位置信息。Optionally, the multiple rendering tasks include location information corresponding to the multiple rendering tasks.
可选地,在将所述渲染任务列表进行多线程渲染之前,判定线程池是否处于满负荷状态。Optionally, before performing multi-thread rendering on the rendering task list, it is determined whether the thread pool is in a full load state.
可选地,当线程池未满负荷时,当前提交渲染任务的线程将当前渲染任务提交给所述线程池进行多线程渲染;以及当线程池满负荷时,当前提交渲染任务的线程不再请求使用多线程方式执行渲染任务,而是直接使用当前线程进行渲染。Optionally, when the thread pool is not fully loaded, the thread currently submitting the rendering task submits the current rendering task to the thread pool for multi-thread rendering; and when the thread pool is fully loaded, the thread currently submitting the rendering task no longer requests Use multithreading to perform rendering tasks, but directly use the current thread for rendering.
可选地,在接收到新的渲染请求时,所述线程池开启新的线程执行渲染任务。Optionally, when a new rendering request is received, the thread pool starts a new thread to execute the rendering task.
可选地,将所述多个渲染任务的渲染结果拼接以生成文本包括:按所述多个渲染任务提交的先后顺序将所述多个渲染任务的渲染结果依次拼接以生成文本。Optionally, splicing the rendering results of the multiple rendering tasks to generate the text includes: sequentially splicing the rendering results of the multiple rendering tasks according to the order in which the multiple rendering tasks are submitted to generate the text.
根据本发明的技术方案,将整个模板文件分解成多个子模板文件,可使每个子模板文件的内容相对较少,从而降低了开发维护成本;每个子模板文件对应一个渲染任务,可以多线程并行获取数据,使得页面中各个模块数据的准备工作更高效,组织数据的逻辑也更清晰,从而开发方式更为高效;将多个渲染任务进行多线程渲染,根据线程池的工作负载情况调整渲染方式,可以在更高效利用服务器CPU资源的同时对服务器CPU资源起到一定的保护作用,不至于在高并发场景下产生过多的渲染线程,从而加剧CPU资源的竞争,是一种可动态伸缩的生成文本的方式。According to the technical solution of the present invention, the entire template file is decomposed into multiple sub-template files, so that the content of each sub-template file is relatively small, thereby reducing development and maintenance costs; each sub-template file corresponds to a rendering task, and can be multi-threaded in parallel Obtaining data makes the data preparation of each module in the page more efficient, and the logic of organizing data is clearer, so that the development method is more efficient; multi-threaded rendering is performed on multiple rendering tasks, and the rendering method is adjusted according to the workload of the thread pool , can protect the server CPU resources while using the server CPU resources more efficiently, so as not to generate too many rendering threads in high-concurrency scenarios, thus intensifying the competition for CPU resources. It is a dynamically scalable The way the text is generated.
附图说明Description of drawings
附图用于更好地理解本发明,不构成对本发明的不当限定。其中:The accompanying drawings are used to better understand the present invention, and do not constitute improper limitations to the present invention. in:
图1是根据本发明实施例的一种可伸缩的生成文本的方法的主要步骤示意图;Fig. 1 is a schematic diagram of main steps of a scalable method for generating text according to an embodiment of the present invention;
图2是根据本发明实施例的一种可伸缩的生成文本的方法的详细步骤流程图。Fig. 2 is a flow chart of detailed steps of a scalable method for generating text according to an embodiment of the present invention.
具体实施方式Detailed ways
以下结合附图对本发明的示范性实施例做出说明,其中包括本发明实施例的各种细节以助于理解,应当将它们认为仅仅是示范性的。因此,本领域普通技术人员应当认识到,可以对这里描述的实施例做出各种改变和修改,而不会背离本发明的范围和精神。同样,为了清楚和简明,以下的描述中省略了对公知功能和结构的描述。Exemplary embodiments of the present invention are described below in conjunction with the accompanying drawings, which include various details of the embodiments of the present invention to facilitate understanding, and they should be regarded as exemplary only. Accordingly, those of ordinary skill in the art will recognize that various changes and modifications of the embodiments described herein can be made without departing from the scope and spirit of the invention. Also, descriptions of well-known functions and constructions are omitted in the following description for clarity and conciseness.
图1是根据本发明实施例的一种可伸缩的生成文本的方法的主要步骤示意图。如图1所示,本发明实施例的一种可伸缩的生成文本的方法主要包括如下的步骤S11至步骤S14。Fig. 1 is a schematic diagram of main steps of a scalable method for generating text according to an embodiment of the present invention. As shown in FIG. 1 , a scalable text generation method according to an embodiment of the present invention mainly includes the following steps S11 to S14.
步骤S11:将整个模板文件分解成多个子模板文件。该步骤可以通过以下两种方案执行:Step S11: Decompose the entire template file into multiple sub-template files. This step can be performed through the following two options:
方案一,将文本中的变量按照模板引擎的语法替换成Java对象的引用生成整个模板文件;以及分解成多个子模板文件。Solution 1, replace the variables in the text with references to Java objects according to the syntax of the template engine to generate the entire template file; and decompose it into multiple sub-template files.
方案二,将文本中的变量分解成多个小组;以及将每个小组的变量按照模板引擎的语法替换成Java对象的引用生成子模板文件。The second solution is to decompose the variables in the text into multiple groups; and replace the variables of each group with Java object references according to the syntax of the template engine to generate sub-template files.
在实际应用中,可以根据所需要渲染的文本的页面结构、程序编写及维护的难易程度等来灵活决定选用哪种方案。In practical applications, you can flexibly decide which solution to choose according to the page structure of the text to be rendered, the difficulty of program writing and maintenance, etc.
将整个模板文件分解成多个子模板文件,原则上是将整个模板文件,按页面结构和所估计的数据准备所需要的时间的长短,分解成多个子模板文件。通常情况下,可将多个比较耗时的接口分解到不同的渲染任务中,以保证多个任务耗时的均衡性。Decomposing the entire template file into multiple sub-template files is, in principle, decomposing the entire template file into multiple sub-template files according to the page structure and the estimated time required for data preparation. Usually, multiple time-consuming interfaces can be decomposed into different rendering tasks to ensure the time-consuming balance of multiple tasks.
步骤S12:生成渲染任务列表,所述渲染任务列表中包含多个渲染任务,所述多个渲染任务用于关联该多个渲染任务对应的所述多个子模板文件,同时实现渲染前准备数据的逻辑。Step S12: Generate a rendering task list, the rendering task list includes a plurality of rendering tasks, the plurality of rendering tasks are used to associate the plurality of sub-template files corresponding to the plurality of rendering tasks, and at the same time realize the preparation of data before rendering logic.
按照步骤S11生成的每个子模板文件分别对应关联一个渲染任务,所有子模板文件对应关联的渲染任务是依次提交给线程池进行渲染的。同时,渲染任务还可以实现渲染前准备数据的逻辑,即:Java后台单线程依次组装模板文件所需要的数据。由于渲染任务列表包含有多个渲染任务,因此可以多线程同时组装多个子模板文件所需要的数据,从而大大节省了准备数据的时间。Each sub-template file generated according to step S11 is associated with a rendering task, and the rendering tasks associated with all sub-template files are sequentially submitted to the thread pool for rendering. At the same time, the rendering task can also implement the logic of preparing data before rendering, that is, a single thread in the Java background sequentially assembles the data required by the template file. Since the rendering task list contains multiple rendering tasks, the data required by multiple sub-template files can be assembled simultaneously in multiple threads, thereby greatly saving the time for data preparation.
所述多个渲染任务包含与所述多个渲染任务相对应的位置信息。在将整个模板文件分解成多个子模板文件时,会按照页面结构等情况来进行分解,此时每个子模板文件应包含其在整个模板文件中的位置信息,以便渲染完成后进行结果拼接,生成相应的文本。The plurality of rendering tasks include location information corresponding to the plurality of rendering tasks. When the entire template file is decomposed into multiple sub-template files, it will be decomposed according to the page structure and other conditions. At this time, each sub-template file should contain its position information in the entire template file, so that the results can be spliced after rendering. corresponding text.
步骤S13:将所述多个渲染任务进行多线程渲染。当步骤S12完成后,提交渲染任务的线程将所述多个渲染任务提交给线程池进行多线程同时渲染。Step S13: performing multi-thread rendering on the plurality of rendering tasks. After step S12 is completed, the thread that submitted the rendering task submits the plurality of rendering tasks to the thread pool for multi-thread simultaneous rendering.
在将所述渲染任务列表进行多线程渲染之前,先判定线程池是否处于满负荷状态。Before performing multi-thread rendering on the rendering task list, it is first determined whether the thread pool is in a full load state.
当线程池未满负荷时,当前提交渲染任务的线程将当前渲染任务提交给所述线程池进行多线程渲染。在接收到新的渲染请求时,所述线程池开启新的线程执行渲染任务。When the thread pool is not fully loaded, the thread that currently submits the rendering task submits the current rendering task to the thread pool for multi-thread rendering. When receiving a new rendering request, the thread pool starts a new thread to execute the rendering task.
当线程池满负荷时,当前提交渲染任务的线程不再请求使用多线程方式执行渲染任务,而是直接使用当前线程进行渲染。When the thread pool is full, the thread that currently submits the rendering task no longer requests to execute the rendering task in a multi-threaded manner, but directly uses the current thread for rendering.
当渲染任务完成后,将渲染结果保存在各线程指定的对象中。When the rendering task is completed, save the rendering result in the object specified by each thread.
步骤S14:将所述多个渲染任务的渲染结果拼接以生成文本。当渲染任务列表中的所有渲染任务完成后,以所述多个渲染任务提交的先后顺序将所述多个渲染任务的渲染结果依次拼接,生成整个文本页面。Step S14: Merge the rendering results of the multiple rendering tasks to generate text. After all the rendering tasks in the rendering task list are completed, the rendering results of the multiple rendering tasks are sequentially spliced in the order in which the multiple rendering tasks are submitted to generate the entire text page.
由步骤S11至步骤S14可以看出,将整个模板文件分解成多个子模板文件,因此每个子模板文件的内容相对较少,从而降低了开发维护成本;每个子模板文件对应一个渲染任务,可以多线程并行获取数据,使得页面中各个模块数据的准备工作更高效,组织数据的逻辑也更清晰,从而开发方式更为高效;将多个渲染任务多线程渲染,根据线程池的工作负载情况调整渲染方式,可以在更高效利用服务器CPU资源的同时对服务器CPU资源起到一定的保护作用,不至于在高并发场景下产生过多的渲染线程,从而加剧CPU资源的竞争,是一种可动态伸缩的生成文本的方式。It can be seen from steps S11 to S14 that the entire template file is decomposed into multiple sub-template files, so the content of each sub-template file is relatively small, thereby reducing development and maintenance costs; each sub-template file corresponds to a rendering task, which can be multi- Threads acquire data in parallel, which makes the data preparation of each module in the page more efficient, and the logic of organizing data is clearer, so that the development method is more efficient; multiple rendering tasks are multi-threaded, and the rendering is adjusted according to the workload of the thread pool The method can protect the server CPU resources while using the server CPU resources more efficiently, so as not to generate too many rendering threads in high concurrency scenarios, thereby intensifying the competition for CPU resources. It is a dynamically scalable way of generating text.
图2是根据本发明实施例的一种可伸缩的生成文本的方法的详细步骤流程图。Fig. 2 is a flow chart of detailed steps of a scalable method for generating text according to an embodiment of the present invention.
如图2所示,以用基于Java的模板引擎Velocity渲染文本页面为例进行说明。为了实现将整个模板文件分解成多个子模板文件(步骤S21),可以采用如下两种方法:As shown in Figure 2, it is illustrated by using the Java-based template engine Velocity to render a text page as an example. In order to decompose the entire template file into multiple sub-template files (step S21), the following two methods can be used:
1、先将整个文本页面中的变量按照Velocity语法替换成Java对象的引用生成Velocity模板文件,再根据文本的页面结构和所估计的数据准备所需要的时间的长短等将Velocity模板文件分解成多个子Velocity模板文件。1. First replace the variables in the entire text page with references to Java objects according to the Velocity syntax to generate a Velocity template file, and then decompose the Velocity template file into multiple parts according to the page structure of the text and the estimated time required for data preparation. A child Velocity template file.
2、先将整个文本页面中的变量根据文本的页面结构和所估计的数据准备所需要的时间的长短等分解成多个小组,再将各个小组的变量按照Velocity语法替换成Java对象的引用生成Velocity模板文件。2. First decompose the variables in the entire text page into multiple groups according to the page structure of the text and the estimated time required for data preparation, and then replace the variables in each group with references to Java objects according to the Velocity syntax. Velocity template files.
完成步骤S21后,根据生成的各个子Velocity模板文件,编写对应的渲染任务,以关联渲染任务及其对应的子Velocity模板文件,同时实现渲染前准备数据的逻辑。渲染任务有多个,以渲染任务列表的形式被提交给渲染工厂进行渲染(步骤S22)。渲染工厂用于对渲染任务进行渲染并将渲染结果拼接以生成文本。渲染工厂中包含有线程池,在接收到渲染任务之前,渲染工厂先进行初始化操作,例如,可设置渲染工厂的线程池大小、最小线程数和工作队列大小等。当渲染工厂接收到渲染任务后,先遍历接收到的渲染任务列表,之后初始化渲染任务,并向渲染任务传入渲染任务总数量等信息,然后根据渲染任务的特征,为其注入公共工具类等可以共享的变量,再采用多线程的方式渲染上述多个子Velocity模板文件(步骤S23)。After step S21 is completed, according to each generated sub-Velocity template file, write a corresponding rendering task to associate the rendering task with its corresponding sub-Velocity template file, and at the same time realize the logic of preparing data before rendering. There are multiple rendering tasks, which are submitted to the rendering factory in the form of a rendering task list for rendering (step S22). The rendering factory is used to render rendering tasks and stitch the rendering results to generate text. The rendering factory contains a thread pool. Before receiving a rendering task, the rendering factory first performs an initialization operation. For example, the size of the thread pool, the minimum number of threads, and the size of the work queue can be set for the rendering factory. When the rendering factory receives the rendering task, it first traverses the received rendering task list, then initializes the rendering task, and passes information such as the total number of rendering tasks to the rendering task, and then injects public tools into it according to the characteristics of the rendering task, etc. Variables that can be shared, and then render the above-mentioned multiple sub-Velocity template files in a multi-threaded manner (step S23).
在将渲染任务列表进行多线程渲染之前,需要判定渲染工厂对应的线程池是否处于满负荷状态(步骤S24)。当线程池满负荷时,当前提交渲染任务的线程不再请求使用多线程方式执行渲染任务,而是直接使用当前线程进行渲染(步骤S25)。当线程池未满负荷时,当前提交渲染任务的线程将当前渲染任务提交给线程池进行多线程渲染,此时渲染工厂的线程池开启一个新的线程执行渲染任务(步骤S26)。当各个线程渲染任务完成后,将渲染结果保存在各个线程的指定对象中(步骤S27),然后检查渲染任务列表是否执行完毕(步骤S28),若没有执行完毕,则转向步骤S23,若已执行完毕,则按照渲染任务提交的先后顺序将所述多个渲染任务的渲染结果依次拼接(步骤S29),以生成一个完整的文本页面。Before performing multi-thread rendering on the rendering task list, it is necessary to determine whether the thread pool corresponding to the rendering factory is in a full load state (step S24). When the thread pool is fully loaded, the thread currently submitting the rendering task no longer requests to execute the rendering task in a multi-threaded manner, but directly uses the current thread for rendering (step S25). When the thread pool is not fully loaded, the thread that currently submits the rendering task submits the current rendering task to the thread pool for multi-thread rendering. At this time, the thread pool of the rendering factory opens a new thread to perform the rendering task (step S26). After each thread rendering task is completed, save the rendering result in the designated object of each thread (step S27), then check whether the rendering task list has been executed (step S28), if not, turn to step S23, if executed After completion, the rendering results of the multiple rendering tasks are sequentially spliced according to the order in which the rendering tasks are submitted (step S29 ), so as to generate a complete text page.
由上述优选实施例可以看出,本发明提出的可伸缩的生成文本的方法,在利用多线程进行渲染时可以根据线程池的工作负载情况调整渲染方式,在线程池已占用线程数较少时,可利用多线程渲染文本,在线程池已占用线程数较多时改变成单线程渲染方式,并且在已占用线程数减少后又可以恢复成多线程渲染,加快了文本页面生成速度,从而节省了生成文本页面的时间。It can be seen from the above preferred embodiments that the scalable text generation method proposed by the present invention can adjust the rendering mode according to the workload of the thread pool when rendering with multiple threads. When the number of threads occupied by the thread pool is small , you can use multi-thread to render text, change to single-thread rendering when the thread pool has a large number of occupied threads, and return to multi-thread rendering after the number of occupied threads decreases, which speeds up the generation of text pages and saves The time the text page was generated.
本发明不仅仅是通过提交渲染任务前检测线程池状态的方式提供了一种高效利用CPU的方法,同样还提出了一种将Velocity模板数据分解到多个渲染任务中,由多线程执行渲染并行获取数据的方法,使得页面中各个模块数据的准备工作更高效的同时,组织数据的逻辑也更清晰,是一种更高效的开发方式。The present invention not only provides a method of efficiently utilizing the CPU by detecting the state of the thread pool before submitting the rendering task, but also proposes a method of decomposing the Velocity template data into multiple rendering tasks, and the rendering is performed by multiple threads in parallel. The method of obtaining data makes the data preparation of each module in the page more efficient, and at the same time, the logic of organizing data is also clearer, which is a more efficient development method.
以上结合具体实施例描述了本发明的基本原理,在本发明的装置和方法中,显然,各部件或各步骤是可以分解和/或重新组合的。这些分解和/或重新组合应视为本发明的等效方案。并且,执行上述系列处理的步骤可以自然地按照说明的顺序按时间顺序执行,但是并不需要一定按照时间顺序执行。某些步骤可以并行或彼此独立地执行。The basic principles of the present invention have been described above in conjunction with specific embodiments. In the device and method of the present invention, obviously, each component or each step can be decomposed and/or reassembled. These decompositions and/or recombinations should be considered equivalents of the present invention. Also, the steps for performing the above series of processes may naturally be performed in chronological order in the order described, but need not necessarily be performed in chronological order. Certain steps may be performed in parallel or independently of each other.
上述具体实施方式,并不构成对本发明保护范围的限制。本领域技术人员应该明白的是,取决于设计要求和其他因素,可以发生各种各样的修改、组合、子组合和替代。任何在本发明的精神和原则之内所作的修改、等同替换和改进等,均应包含在本发明保护范围之内。The above specific implementation methods do not constitute a limitation to the protection scope of the present invention. It should be apparent to those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modifications, equivalent replacements and improvements made within the spirit and principles of the present invention shall be included within the protection scope of the present invention.
Claims (9)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201510267434.2A CN104881320B (en) | 2015-05-22 | 2015-05-22 | A kind of telescopic method for generating text |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201510267434.2A CN104881320B (en) | 2015-05-22 | 2015-05-22 | A kind of telescopic method for generating text |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN104881320A true CN104881320A (en) | 2015-09-02 |
| CN104881320B CN104881320B (en) | 2018-11-27 |
Family
ID=53948826
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201510267434.2A Active CN104881320B (en) | 2015-05-22 | 2015-05-22 | A kind of telescopic method for generating text |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN104881320B (en) |
Cited By (24)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN106502794A (en) * | 2016-10-24 | 2017-03-15 | 深圳市彬讯科技有限公司 | A kind of efficient rendering intent of the 3 d effect graph rendered based on high in the clouds |
| US9600471B2 (en) | 2012-11-02 | 2017-03-21 | Arria Data2Text Limited | Method and apparatus for aggregating with information generalization |
| US9640045B2 (en) | 2012-08-30 | 2017-05-02 | Arria Data2Text Limited | Method and apparatus for alert validation |
| CN107643889A (en) * | 2016-07-20 | 2018-01-30 | 平安科技(深圳)有限公司 | Page rendering method and apparatus based on template engine |
| US9904676B2 (en) | 2012-11-16 | 2018-02-27 | Arria Data2Text Limited | Method and apparatus for expressing time in an output text |
| US9946711B2 (en) | 2013-08-29 | 2018-04-17 | Arria Data2Text Limited | Text generation from correlated alerts |
| US9990360B2 (en) | 2012-12-27 | 2018-06-05 | Arria Data2Text Limited | Method and apparatus for motion description |
| US10115202B2 (en) | 2012-12-27 | 2018-10-30 | Arria Data2Text Limited | Method and apparatus for motion detection |
| CN109032793A (en) * | 2018-07-11 | 2018-12-18 | Oppo广东移动通信有限公司 | Method, apparatus, terminal and the storage medium of resource distribution |
| US10255252B2 (en) | 2013-09-16 | 2019-04-09 | Arria Data2Text Limited | Method and apparatus for interactive reports |
| US10282878B2 (en) | 2012-08-30 | 2019-05-07 | Arria Data2Text Limited | Method and apparatus for annotating a graphical output |
| US10282422B2 (en) | 2013-09-16 | 2019-05-07 | Arria Data2Text Limited | Method, apparatus, and computer program product for user-directed reporting |
| US10445432B1 (en) | 2016-08-31 | 2019-10-15 | Arria Data2Text Limited | Method and apparatus for lightweight multilingual natural language realizer |
| US10467347B1 (en) | 2016-10-31 | 2019-11-05 | Arria Data2Text Limited | Method and apparatus for natural language document orchestrator |
| US10467333B2 (en) | 2012-08-30 | 2019-11-05 | Arria Data2Text Limited | Method and apparatus for updating a previously generated text |
| CN110764849A (en) * | 2018-07-25 | 2020-02-07 | 优视科技有限公司 | Rendering method and device for user interface, client device and electronic device |
| US10565308B2 (en) | 2012-08-30 | 2020-02-18 | Arria Data2Text Limited | Method and apparatus for configurable microplanning |
| US10664558B2 (en) | 2014-04-18 | 2020-05-26 | Arria Data2Text Limited | Method and apparatus for document planning |
| US10769380B2 (en) | 2012-08-30 | 2020-09-08 | Arria Data2Text Limited | Method and apparatus for situational analysis text generation |
| US10776561B2 (en) | 2013-01-15 | 2020-09-15 | Arria Data2Text Limited | Method and apparatus for generating a linguistic representation of raw input data |
| CN112241289A (en) * | 2019-07-18 | 2021-01-19 | 中移(苏州)软件技术有限公司 | A text data processing method and electronic device |
| CN112256994A (en) * | 2020-10-20 | 2021-01-22 | 中企动力科技股份有限公司 | Template rendering method and device, electronic equipment and storage medium |
| US11176214B2 (en) | 2012-11-16 | 2021-11-16 | Arria Data2Text Limited | Method and apparatus for spatial descriptions in an output text |
| CN113923519A (en) * | 2021-11-11 | 2022-01-11 | 深圳万兴软件有限公司 | Video rendering method and device, computer equipment and storage medium |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN1987792A (en) * | 2006-12-20 | 2007-06-27 | 金魁 | Application system for high grade multiple line distance management |
| CN101938396A (en) * | 2009-06-30 | 2011-01-05 | 华为技术有限公司 | Data flow control method and device |
| US20120110433A1 (en) * | 2010-10-28 | 2012-05-03 | Microsoft Corporation | Parallel web page processing |
| CN103605498A (en) * | 2013-12-05 | 2014-02-26 | 用友软件股份有限公司 | Method and system for multi-thread execution of single-thread task |
| CN103761317A (en) * | 2014-01-27 | 2014-04-30 | 北京京东尚科信息技术有限公司 | Multithreading asynchronous rendering system and method |
-
2015
- 2015-05-22 CN CN201510267434.2A patent/CN104881320B/en active Active
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN1987792A (en) * | 2006-12-20 | 2007-06-27 | 金魁 | Application system for high grade multiple line distance management |
| CN101938396A (en) * | 2009-06-30 | 2011-01-05 | 华为技术有限公司 | Data flow control method and device |
| US20120110433A1 (en) * | 2010-10-28 | 2012-05-03 | Microsoft Corporation | Parallel web page processing |
| CN103605498A (en) * | 2013-12-05 | 2014-02-26 | 用友软件股份有限公司 | Method and system for multi-thread execution of single-thread task |
| CN103761317A (en) * | 2014-01-27 | 2014-04-30 | 北京京东尚科信息技术有限公司 | Multithreading asynchronous rendering system and method |
Cited By (44)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US10565308B2 (en) | 2012-08-30 | 2020-02-18 | Arria Data2Text Limited | Method and apparatus for configurable microplanning |
| US10504338B2 (en) | 2012-08-30 | 2019-12-10 | Arria Data2Text Limited | Method and apparatus for alert validation |
| US9640045B2 (en) | 2012-08-30 | 2017-05-02 | Arria Data2Text Limited | Method and apparatus for alert validation |
| US10769380B2 (en) | 2012-08-30 | 2020-09-08 | Arria Data2Text Limited | Method and apparatus for situational analysis text generation |
| US10839580B2 (en) | 2012-08-30 | 2020-11-17 | Arria Data2Text Limited | Method and apparatus for annotating a graphical output |
| US10282878B2 (en) | 2012-08-30 | 2019-05-07 | Arria Data2Text Limited | Method and apparatus for annotating a graphical output |
| US10467333B2 (en) | 2012-08-30 | 2019-11-05 | Arria Data2Text Limited | Method and apparatus for updating a previously generated text |
| US10026274B2 (en) | 2012-08-30 | 2018-07-17 | Arria Data2Text Limited | Method and apparatus for alert validation |
| US10963628B2 (en) | 2012-08-30 | 2021-03-30 | Arria Data2Text Limited | Method and apparatus for updating a previously generated text |
| US9600471B2 (en) | 2012-11-02 | 2017-03-21 | Arria Data2Text Limited | Method and apparatus for aggregating with information generalization |
| US10216728B2 (en) | 2012-11-02 | 2019-02-26 | Arria Data2Text Limited | Method and apparatus for aggregating with information generalization |
| US10311145B2 (en) | 2012-11-16 | 2019-06-04 | Arria Data2Text Limited | Method and apparatus for expressing time in an output text |
| US11176214B2 (en) | 2012-11-16 | 2021-11-16 | Arria Data2Text Limited | Method and apparatus for spatial descriptions in an output text |
| US11580308B2 (en) | 2012-11-16 | 2023-02-14 | Arria Data2Text Limited | Method and apparatus for expressing time in an output text |
| US9904676B2 (en) | 2012-11-16 | 2018-02-27 | Arria Data2Text Limited | Method and apparatus for expressing time in an output text |
| US10853584B2 (en) | 2012-11-16 | 2020-12-01 | Arria Data2Text Limited | Method and apparatus for expressing time in an output text |
| US9990360B2 (en) | 2012-12-27 | 2018-06-05 | Arria Data2Text Limited | Method and apparatus for motion description |
| US10860810B2 (en) | 2012-12-27 | 2020-12-08 | Arria Data2Text Limited | Method and apparatus for motion description |
| US10115202B2 (en) | 2012-12-27 | 2018-10-30 | Arria Data2Text Limited | Method and apparatus for motion detection |
| US10803599B2 (en) | 2012-12-27 | 2020-10-13 | Arria Data2Text Limited | Method and apparatus for motion detection |
| US10776561B2 (en) | 2013-01-15 | 2020-09-15 | Arria Data2Text Limited | Method and apparatus for generating a linguistic representation of raw input data |
| US9946711B2 (en) | 2013-08-29 | 2018-04-17 | Arria Data2Text Limited | Text generation from correlated alerts |
| US10671815B2 (en) | 2013-08-29 | 2020-06-02 | Arria Data2Text Limited | Text generation from correlated alerts |
| US10860812B2 (en) | 2013-09-16 | 2020-12-08 | Arria Data2Text Limited | Method, apparatus, and computer program product for user-directed reporting |
| US10255252B2 (en) | 2013-09-16 | 2019-04-09 | Arria Data2Text Limited | Method and apparatus for interactive reports |
| US11144709B2 (en) | 2013-09-16 | 2021-10-12 | Arria Data2Text Limited | Method and apparatus for interactive reports |
| US10282422B2 (en) | 2013-09-16 | 2019-05-07 | Arria Data2Text Limited | Method, apparatus, and computer program product for user-directed reporting |
| US10664558B2 (en) | 2014-04-18 | 2020-05-26 | Arria Data2Text Limited | Method and apparatus for document planning |
| CN107643889B (en) * | 2016-07-20 | 2020-03-24 | 平安科技(深圳)有限公司 | Page rendering method and device based on template engine |
| CN107643889A (en) * | 2016-07-20 | 2018-01-30 | 平安科技(深圳)有限公司 | Page rendering method and apparatus based on template engine |
| US10445432B1 (en) | 2016-08-31 | 2019-10-15 | Arria Data2Text Limited | Method and apparatus for lightweight multilingual natural language realizer |
| US10853586B2 (en) | 2016-08-31 | 2020-12-01 | Arria Data2Text Limited | Method and apparatus for lightweight multilingual natural language realizer |
| CN106502794A (en) * | 2016-10-24 | 2017-03-15 | 深圳市彬讯科技有限公司 | A kind of efficient rendering intent of the 3 d effect graph rendered based on high in the clouds |
| CN106502794B (en) * | 2016-10-24 | 2019-10-11 | 深圳市彬讯科技有限公司 | A kind of efficient rendering method of 3 d effect graph based on cloud rendering |
| US10467347B1 (en) | 2016-10-31 | 2019-11-05 | Arria Data2Text Limited | Method and apparatus for natural language document orchestrator |
| US10963650B2 (en) | 2016-10-31 | 2021-03-30 | Arria Data2Text Limited | Method and apparatus for natural language document orchestrator |
| US11727222B2 (en) | 2016-10-31 | 2023-08-15 | Arria Data2Text Limited | Method and apparatus for natural language document orchestrator |
| CN109032793A (en) * | 2018-07-11 | 2018-12-18 | Oppo广东移动通信有限公司 | Method, apparatus, terminal and the storage medium of resource distribution |
| CN110764849A (en) * | 2018-07-25 | 2020-02-07 | 优视科技有限公司 | Rendering method and device for user interface, client device and electronic device |
| CN112241289A (en) * | 2019-07-18 | 2021-01-19 | 中移(苏州)软件技术有限公司 | A text data processing method and electronic device |
| CN112241289B (en) * | 2019-07-18 | 2022-12-13 | 中移(苏州)软件技术有限公司 | Text data processing method and electronic equipment |
| CN112256994A (en) * | 2020-10-20 | 2021-01-22 | 中企动力科技股份有限公司 | Template rendering method and device, electronic equipment and storage medium |
| CN113923519A (en) * | 2021-11-11 | 2022-01-11 | 深圳万兴软件有限公司 | Video rendering method and device, computer equipment and storage medium |
| CN113923519B (en) * | 2021-11-11 | 2024-02-13 | 深圳万兴软件有限公司 | Video rendering method, device, computer equipment and storage medium |
Also Published As
| Publication number | Publication date |
|---|---|
| CN104881320B (en) | 2018-11-27 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN104881320A (en) | Scalable text generation method | |
| US8601458B2 (en) | Profile-driven data stream processing | |
| CN103761317B (en) | A kind of asynchronous rendering system of multithreading and method | |
| US9323619B2 (en) | Deploying parallel data integration applications to distributed computing environments | |
| KR20210040850A (en) | Method, apparatus, device, and storage medium for parsing document | |
| CN103605498B (en) | The multithreading of mono-thread tasks performs method and system | |
| US9477511B2 (en) | Task-based modeling for parallel data integration | |
| US9471651B2 (en) | Adjustment of map reduce execution | |
| CN110795219A (en) | Resource scheduling method and system suitable for multiple computing frameworks | |
| CN106020823A (en) | A way to separate front-end Web presentation and data and to quickly respond to pages | |
| CN101604241A (en) | A Code Generation Method for Embedded System | |
| US20150205633A1 (en) | Task management in single-threaded environments | |
| CN104317591A (en) | OSGi (open service gateway initiative)-based web interface frame system and web business processing method thereof | |
| CN105095425B (en) | A kind of inter-library method and device of carrying down of database | |
| WO2018045753A1 (en) | Method and device for distributed graph computation | |
| JP5478526B2 (en) | Data analysis and machine learning processing apparatus, method and program | |
| CN102542047A (en) | Task logic library generating method, task logic library generating system, data processing method and data processing system | |
| CN102521024A (en) | Job scheduling method based on bioinformation cloud platform | |
| CN106502773A (en) | There is data asynchronous processing method and the module of synchronous callback information function | |
| CN101876895A (en) | Encapsulation and Integration Method of Application Software in Grid Computing Environment | |
| CN112035230A (en) | Method and device for generating task scheduling file and storage medium | |
| Berkowitz | Metaq: Bundle supercomputing tasks | |
| CN108536696A (en) | A kind of database personalized self-service query platform and method | |
| CN104423897B (en) | Expansible printed text pretreatment system | |
| CN104408167A (en) | Method for expanding sqoop function in Hue based on django |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| C06 | Publication | ||
| PB01 | Publication | ||
| EXSB | Decision made by sipo to initiate substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |