이 콘텐츠는 선택한 언어로 제공되지 않습니다.

2.2. Executing Your First Process


To execute your process, right-click on RuleFlowTest.java and select Run As..., followed by Java Application.
When the process executes, the following output will appear in the Console window:
Hello World
Copy to Clipboard Toggle word wrap
Look at the code of RuleFlowTest class:
package com.sample;

import org.drools.KnowledgeBase;
import org.drools.builder.KnowledgeBuilder;
import org.drools.builder.KnowledgeBuilderFactory;
import org.drools.builder.ResourceType;
import org.drools.io.ResourceFactory;
import org.drools.logger.KnowledgeRuntimeLogger;
import org.drools.logger.KnowledgeRuntimeLoggerFactory;
import org.drools.runtime.StatefulKnowledgeSession;

/**
 * This is a sample file to launch a process.
 */
public class ProcessTest {

  public static final void main(String[] args) {
    try {
      // load up the knowledge base
      KnowledgeBase kbase = readKnowledgeBase();
      StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
      KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
      // start a new process instance
      ksession.startProcess("com.sample.ruleflow");
      logger.close();
    } catch (Throwable t) {
      t.printStackTrace();
    }
  }

  private static KnowledgeBase readKnowledgeBase() throws Exception {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newClassPathResource("ruleflow.rf"), ResourceType.DRF);
    return kbuilder.newKnowledgeBase();
  }

}
Copy to Clipboard Toggle word wrap
As you can see, the execution process is made up of a number of steps:
  1. Firstly, a knowledge base is created. A knowledge base contains all the knowledge (such as words, processes, rules, and so forth) that are needed by your application. This knowledge base is usually created once, and then reused multiple times. In this case, the knowledge base consists of the sample process only.
  2. Next, a session for interaction with the engine is generated.
    A logger is then added to the session. This records all execution events and make it easier for you to visualize what is happening.
  3. Finally, you can start a new instance of the process by invoking the startProcess(String processId) method on the session. When you do this, your process instance begins to run, resulting in the executions of the Start node, the Action node, and the End node in order. When they finish the process instance will conclude.
Because you added a logger to the session, you can review what happened by looking at the audit log:
Select the Audit View tab on the bottom right of the window, (next to the Console tab.)
Click on the Open Log button (the first one on the right) and navigate to the newly created test.log file (in your project directory.)

Note

If you are not sure where this project directory is located, right-click on it and you will find the location listed in the Resource section
A tree view will appear. This shows the events that occurred at run-time. Events that were executed as the direct result of another event are shown as the children of that event.
This log shows that after starting the process, the Start node, the Action node and the End node were triggered, in that order, after which the process instance was completed.
You can now start to experiment by designing your own process by modifying the example. To validate your processes, click on the Check the rule-flow model button (this is the green check box action in the upper tool-bar that appears when you are editing a process.) Processes are also automatically validated when you save them. You can see the debugging information in the Error View.
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2026 Red Hat
맨 위로 이동