Java coprocessor Framework--kilim frequently asked questions

Source: Internet
Author: User

Task in 1.Kilim, that is, how the user thread schedules and switches? In multi-task scheduling, there are two methods of preemptive and cooperative in operating system, compared with traditional thread-multithreading preemptive scheduling, the task in Kilim is cooperative scheduling, that is, the task itself is responsible for releasing and recovering CPU.
2.Kilim how to identify which methods in the code are pauseable and can be paused? After compiling the code, the Weaver tool provided by Kilim analyzes the bytecode generated by the compilation, and identifies which methods throw the pauseable exception, to judge how the recognition method can be paused.
How does 3.Kilim implement the pause and resume of a task during thread execution? The Kilim is woven through the compile-time bytecode, and each of the paused methods is byte-coded to handle the execution context before and after the method is executed:
    • When a task pauses, the stack frame of the current function in the function call chain is staged into the statestack of fiber, and the ispausing of the fiber is set to true, and then the byte code instruction return is called to return the upper function. The upper function is determined by the variables in the fiber to get the function to pause the return, the stack frame of the function is staged into the statestack of fiber, and then returned directly, and so on, and so on, and so on, the layer upward until the return to the workerthread of the Run method body, This task then implements the pause.
    • Task recovery execution is done by observing the task as a mailbox when paused, and subsequent when mailbox has received a message that triggers the Observer, the task in the callback function will rejoin itself to the Runnabletask queue of the Scheduler scheduler. And wake up worker thread workerthread execution.
How is the Weaver tool in 4.Kilim woven into the code for compilation? Bytecode technology, specifically through the ASM bytecode framework implementation of the compilation of the generated class file to enhance.
5. How to transform a traditional thread execution method into a Kilim task?
    • First, you need to implement a class to inherit the task, implement the task's Execute method, the business logic is no longer the thread of the Run method body, but placed in the task's Execute method body.
    • The method called in the Execute method, if it is possible to pause, must declare the throw pauseable exception, otherwise it may not need to be thrown.
    • Communication between tasks passes messages through mailbox mailboxes, with three versions of Put and get, including blocking threads, blocking tasks but not blocking threads, non-blocking.
    • When compiling against these task and pauseable methods, it is necessary to weave with the Weaver tools provided by Kilim, and the runtime will be abnormal if not woven.
    • Note For methods in Kilim: One pauseable method can only be called by another pauseable method.
What actions in 6.Kilim can cause a task to pause or resume running?
    • Task.sleep () to suspend the current task for a period of time
    • Task.yield () enables the current task to pause and abort the run
    • Task.pause () to suspend execution of the current task
    • Task.resume () enables the current task to resume execution
    • Mailbox.get () enables the current task to pause execution until the Mailbox queue is not empty.
7. What scenarios are suitable for application Kilim? IO-intensive applications are more suitable for use of the process, such as the existence of more network interaction with the backend, there is more time waiting for the backend response, can ensure that the thread does not block waiting for the network response, the ability to take advantage of multi-core multithreading. For CPU-intensive applications, Kilim does not work well because the CPU is busy in most cases.
How is the dispatch between task and thread in 8.Kilim?

Here is a direct reference to the original text in the Kilim official document to answer:

Kilim ' s tasks is cooperatively scheduled on a kernel thread pool.

A Kilim task is owned and managed by a scheduler, which manages the
Thread pool. When a-task needs to pause, it removes itself from the
Thread by popping it call stack, remembering enough for each
Activation frame in order to help rebuild the stack and resume at a
Later point). The scheduler then reuses this thread for some and other
Task.
What is the amount of memory that a task occupies in 9.Kilim?

Here is a direct reference to the original text in the Kilim official document to answer:

The amount of memory occupied by a task is:
1. The Java object that represents the Task class
2. If paused, an array of activation frames is stored. The Kilim
Weaver performs data flow and live variable and constant analysis
(intra-procedurally) To ensure the IT capture only as
Much as is needed to resume.
3. The contents of all mailboxes, the task is receiving on.

Java coprocessor Framework--kilim frequently asked questions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.