⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 workingmemorysynchronizedproxy.java

📁 drools 一个开放源码的规则引擎
💻 JAVA
字号:
package org.drools.util.concurrent;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

import org.drools.WorkingMemory;

/**
 * Helper class that synchronizes all public methods of WorkingMemory via a
 * <code>java.lang.reflect.Proxy</code>
 */
public class WorkingMemorySynchronizedProxy {

    /**
     * Returns an instance of a proxy class for the specified WorkingMemory in which
     * all method calls are synchronized.
     * @param workingMemory
     * @return A proxy that invokes workingMemory methods within a synchronized block.
     */
    public static WorkingMemory createProxy(final WorkingMemory workingMemory) {
        return (WorkingMemory) Proxy.newProxyInstance(
                WorkingMemory.class.getClassLoader(),
                new Class[]{WorkingMemory.class},
                new InvocationHandler() {
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        synchronized(workingMemory) {
                            return method.invoke(workingMemory, args);
                        }
                    }
                });
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -