Example usage for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList

List of usage examples for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList

Introduction

In this page you can find the example usage for java.util.concurrent CopyOnWriteArrayList CopyOnWriteArrayList.

Prototype

public CopyOnWriteArrayList() 

Source Link

Document

Creates an empty list.

Usage

From source file:Main.java

public static <E> CopyOnWriteArrayList<E> newCopyOnWriteArrayList() {
    return new CopyOnWriteArrayList<E>();
}

From source file:Main.java

/**
 * Create a new concurrent list.//from w ww . java2s  .co m
 *
 * @param <T> The type of value.
 *
 * @return The new concurrent list.
 */
public static <T> List<T> newConcurrentList() {
    return new CopyOnWriteArrayList<T>();
}

From source file:Main.java

/**
 * Creates an empty {@link CopyOnWriteArrayList}. Keep in mind that you 
 * only want to use {@code CopyOnWriteArrayList} for lists that are not 
 * going to be modified very often!/*from   ww w.java 2s  .  c  o m*/
 * 
 * @return A new, empty {@code CopyOnWriteArrayList}.
 */
public static <E> List<E> concurrentList() {
    return new CopyOnWriteArrayList<>();
}

From source file:com.web.server.util.ClassLoaderUtil.java

public static CopyOnWriteArrayList closeClassLoader(ClassLoader cl) {
    CopyOnWriteArrayList jars = new CopyOnWriteArrayList();
    boolean res = false;
    Class classURLClassLoader = null;
    if (cl instanceof URLClassLoader)
        classURLClassLoader = URLClassLoader.class;
    else if (cl instanceof VFSClassLoader) {
        classURLClassLoader = VFSClassLoader.class;
    }/* ww w . j ava 2  s. c  o m*/
    Field f = null;
    try {
        f = classURLClassLoader.getDeclaredField("ucp");
        System.out.println(f);
    } catch (NoSuchFieldException e1) {
        // e1.printStackTrace();
        // log.info(e1.getMessage(), e1);

    }
    if (f != null) {
        f.setAccessible(true);
        Object obj = null;
        try {
            obj = f.get(cl);
        } catch (IllegalAccessException e1) {
            // e1.printStackTrace();
            // log.info(e1.getMessage(), e1);
        }
        if (obj != null) {
            final Object ucp = obj;
            f = null;
            try {
                f = ucp.getClass().getDeclaredField("loaders");
                System.out.println(f);
            } catch (NoSuchFieldException e1) {
                // e1.printStackTrace();
                // log.info(e1.getMessage(), e1);
            }
            if (f != null) {
                f.setAccessible(true);
                ArrayList loaders = null;
                try {
                    loaders = (ArrayList) f.get(ucp);
                    res = true;
                } catch (IllegalAccessException e1) {
                    // e1.printStackTrace();
                }
                for (int i = 0; loaders != null && i < loaders.size(); i++) {
                    obj = loaders.get(i);
                    f = null;
                    try {
                        f = obj.getClass().getDeclaredField("jar");
                        // log.info(f);
                    } catch (NoSuchFieldException e) {
                        // e.printStackTrace();
                        // log.info(e.getMessage(), e);
                    }
                    if (f != null) {
                        f.setAccessible(true);
                        try {
                            obj = f.get(obj);
                        } catch (IllegalAccessException e1) {
                            // e1.printStackTrace();
                            // log.info(e1.getMessage(), e1);
                        }
                        if (obj instanceof JarFile) {
                            final JarFile jarFile = (JarFile) obj;
                            System.out.println(jarFile.getName());
                            jars.add(jarFile.getName().replace("/", "\\").trim().toUpperCase());
                            // try {
                            // jarFile.getManifest().clear();
                            // } catch (IOException e) {
                            // // ignore
                            // }
                            try {
                                jarFile.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                                // ignore
                                // log.info(e.getMessage(), e);
                            }
                        }
                    }
                }
            }
        }
    }
    return jars;
}

From source file:com.app.server.util.ClassLoaderUtil.java

public static CopyOnWriteArrayList closeClassLoader(ClassLoader cl) {
    CopyOnWriteArrayList jars = new CopyOnWriteArrayList();
    boolean res = false;
    Class classURLClassLoader = null;
    if (cl instanceof URLClassLoader) {
        classURLClassLoader = URLClassLoader.class;
        if (cl instanceof WebClassLoader) {
            String url = "";
            CopyOnWriteArrayList webCLUrl = ((WebClassLoader) cl).geturlS();
            for (int index = 0; index < webCLUrl.size(); index++) {

                try {
                    url = ((URL) webCLUrl.get(index)).toURI().toString();
                } catch (URISyntaxException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }/*ww  w.  ja  v  a 2  s.  c  om*/
                jars.add(url.replace("file:", "").replace("/", "\\").toUpperCase());
            }
        }
    } else if (cl instanceof VFSClassLoader) {
        classURLClassLoader = VFSClassLoader.class;
    }
    Field f = null;
    try {
        f = classURLClassLoader.getDeclaredField("ucp");
        //log.info(f);
    } catch (NoSuchFieldException e1) {
        // e1.printStackTrace();
        // log.info(e1.getMessage(), e1);

    }
    if (f != null) {
        f.setAccessible(true);
        Object obj = null;
        try {
            obj = f.get(cl);
        } catch (IllegalAccessException e1) {
            // e1.printStackTrace();
            // log.info(e1.getMessage(), e1);
        }
        if (obj != null) {
            final Object ucp = obj;
            f = null;
            try {
                f = ucp.getClass().getDeclaredField("loaders");
                //log.info(f);
            } catch (NoSuchFieldException e1) {
                // e1.printStackTrace();
                // log.info(e1.getMessage(), e1);
            }
            if (f != null) {
                f.setAccessible(true);
                ArrayList loaders = null;
                try {
                    loaders = (ArrayList) f.get(ucp);
                    res = true;
                } catch (IllegalAccessException e1) {
                    // e1.printStackTrace();
                }
                for (int i = 0; loaders != null && i < loaders.size(); i++) {
                    obj = loaders.get(i);
                    f = null;
                    try {
                        f = obj.getClass().getDeclaredField("jar");
                        // log.info(f);
                    } catch (NoSuchFieldException e) {
                        // e.printStackTrace();
                        // log.info(e.getMessage(), e);
                    }
                    if (f != null) {
                        f.setAccessible(true);
                        try {
                            obj = f.get(obj);
                        } catch (IllegalAccessException e1) {
                            // e1.printStackTrace();
                            // log.info(e1.getMessage(), e1);
                        }
                        if (obj instanceof JarFile) {
                            final JarFile jarFile = (JarFile) obj;
                            //log.info(jarFile.getName());
                            jars.add(jarFile.getName().replace("/", "\\").trim().toUpperCase());
                            // try {
                            // jarFile.getManifest().clear();
                            // } catch (IOException e) {
                            // // ignore
                            // }
                            try {
                                jarFile.close();
                            } catch (IOException e) {
                                e.printStackTrace();
                                // ignore
                                // log.info(e.getMessage(), e);
                            }
                        }
                    }
                }
            }
        }
    }
    return jars;
}

From source file:org.eclipse.flux.core.LiveEditCoordinator.java

public LiveEditCoordinator(IMessagingConnector messagingConnector) {
    this.messagingConnector = messagingConnector;
    this.liveEditConnectors = new CopyOnWriteArrayList<>();

    IMessageHandler startLiveUnit = new AbstractMessageHandler("liveResourceStarted") {
        @Override/*from  w  w w.  ja v a 2  s.c  o  m*/
        public void handleMessage(String messageType, JSONObject message) {
            startLiveUnit(message);
        }
    };
    messagingConnector.addMessageHandler(startLiveUnit);

    IMessageHandler startLiveUnitResponse = new AbstractMessageHandler("liveResourceStartedResponse") {
        @Override
        public void handleMessage(String messageType, JSONObject message) {
            startLiveUnitResponse(message);
        }
    };
    messagingConnector.addMessageHandler(startLiveUnitResponse);

    IMessageHandler modelChangedHandler = new AbstractMessageHandler("liveResourceChanged") {
        @Override
        public void handleMessage(String messageType, JSONObject message) {
            modelChanged(message);
        }
    };
    messagingConnector.addMessageHandler(modelChangedHandler);
}

From source file:org.eclipse.mylyn.internal.commons.repositories.http.core.IdleConnectionMonitorThread.java

public IdleConnectionMonitorThread(long pollingInterval) {
    this.pollingInterval = pollingInterval;
    this.connectionManagers = new CopyOnWriteArrayList<ClientConnectionManager>();
    setDaemon(true);//from   w  ww.  j  ava  2  s. c  o m
}

From source file:com.sm.store.cluster.Utils.java

public static List<String> convertList(String[] strs) {
    List<String> list = new CopyOnWriteArrayList<String>();
    for (String str : strs) {
        list.add(str);// w  w w .  j av a 2s  . c  o m
    }
    return list;
}

From source file:org.obp.remote.RemoteObpLocator.java

public RemoteObpLocator() {
    remotes = new CopyOnWriteArrayList<>();
    remoteInstances = new ConcurrentHashMap<>();
}

From source file:org.openhab.core.items.GroupItem.java

public GroupItem(String name, GenericItem baseItem, GroupFunction function) {
    super(name);//from   w  ww  .  j a  va2  s .  c o m
    members = new CopyOnWriteArrayList<Item>();
    this.function = function;
    this.baseItem = baseItem;
}