[rules-users] KnowledgeBuilder.add(Resource, ResourceType) thread problem?

chriscarr ccarr at esrv.com
Thu Oct 20 18:07:04 EDT 2011


    public static void main(final String[] args)
    {
        // --------------------------------------------------------------
        // Read the resources once just to confirm that they are correct.
        System.out.println("Before First Read...");
        readResource("simple-one.bpmn");
        readResource("simple-two.bpmn");
        System.out.println("After First Read...");

        //
---------------------------------------------------------------------------------------
        // Launch two different threads at once that will run for "N"
seconds and they each try to
        // load a different classpath resource. Eventually, bad things
happen.  The BPMN files are
        // identical and are very simple (start -> 6 sequential empty script
tasks -> end).
        new Thread(new Runnable()
        {
            public void run()
            {
                final long startTime = System.currentTimeMillis();

                while ((System.currentTimeMillis() - startTime) < (30 *
1000))
                {
                    readResource("simple-one.bpmn");
                }
            }
        }).start();

        new Thread(new Runnable()
        {
            public void run()
            {
                final long startTime = System.currentTimeMillis();

                while ((System.currentTimeMillis() - startTime) < (30 *
1000))
                {
                    readResource("simple-two.bpmn");
                }
            }
        }).start();
    }

    private static void readResource(final String bpmnFile)
    {
        final KnowledgeBuilder builder  =
KnowledgeBuilderFactory.newKnowledgeBuilder();
        final Resource         resource =
ResourceFactory.newClassPathResource(bpmnFile, SimpleLoadTest.class);
        builder.add(resource, ResourceType.BPMN2);

        if (builder.hasErrors())
        {
            System.out.println(Thread.currentThread().getName() + ": Found
Error(s): " + builder.getErrors().toString());
        }
    }


--
View this message in context: http://drools.46999.n3.nabble.com/KnowledgeBuilder-add-Resource-ResourceType-thread-problem-tp3439140p3439155.html
Sent from the Drools: User forum mailing list archive at Nabble.com.



More information about the rules-users mailing list