Java Code Examples for java.util.Collections.synchronizedCollection()

The following are Jave code examples for showing how to use synchronizedCollection() of the java.util.Collections class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: VerifyUtils.java   View Source Code Vote up 6 votes
public static Collection<Object> getFilterdMessage(Collection<Object> sendMsgs,
    Collection<Object> recvMsgs) {
    Collection<Object> recvMsgsSync = Collections.synchronizedCollection(recvMsgs);
    Collection<Object> filterdMsgs = new ArrayList<Object>();
    int filterNum = 0;
    for (Object msg : recvMsgsSync) {
        if (sendMsgs.contains(msg)) {
            filterdMsgs.add(msg);
        } else {
            filterNum++;
        }
    }

    logger.info(String.format("[%s] messages is filterd!", filterNum));
    return filterdMsgs;
}
 
Example 2
Project: rmq4note   File: VerifyUtils.java   View Source Code Vote up 6 votes
public static Collection<Object> getFilterdMessage(Collection<Object> sendMsgs,
    Collection<Object> recvMsgs) {
    Collection<Object> recvMsgsSync = Collections.synchronizedCollection(recvMsgs);
    Collection<Object> filterdMsgs = new ArrayList<Object>();
    int filterNum = 0;
    for (Object msg : recvMsgsSync) {
        if (sendMsgs.contains(msg)) {
            filterdMsgs.add(msg);
        } else {
            filterNum++;
        }
    }

    logger.info(String.format("[%s] messages is filterd!", filterNum));
    return filterdMsgs;
}
 
Example 3
Project: incubator-netbeans   File: J2SEPlatformCustomizer.java   View Source Code Vote up 5 votes
@NbBundle.Messages({
    "TXT_JavadocSearch=Searching Javadoc in {0}"
})
private static Collection<? extends URL> findRoot(final File file, final int type) throws MalformedURLException {
    if (type != CLASSPATH) {                
        final FileObject fo = URLMapper.findFileObject(FileUtil.urlForArchiveOrDir(file));
        if (fo != null) {
            final Collection<FileObject> result = Collections.synchronizedCollection(new ArrayList<FileObject>());
            if (type == SOURCES) {
                final FileObject root = JavadocAndSourceRootDetection.findSourceRoot(fo);
                if (root != null) {
                    result.add(root);
                }
            } else if (type == JAVADOC) {
                final AtomicBoolean cancel = new AtomicBoolean();
                class Task implements ProgressRunnable<Void>, Cancellable {
                    @Override
                    public Void run(ProgressHandle handle) {
                        result.addAll(JavadocAndSourceRootDetection.findJavadocRoots(fo, cancel));
                        return null;
                    }

                    @Override
                    public boolean cancel() {
                        cancel.set(true);
                        return true;
                    }
                }
                final ProgressRunnable<Void> task = new Task();
                ProgressUtils.showProgressDialogAndRun(task, Bundle.TXT_JavadocSearch(file.getAbsolutePath()), false);
            }
            if (!result.isEmpty()) {
                return result.stream()
                        .map(FileObject::toURL)
                        .collect(Collectors.toList());
            }                    
        }
    }
    return Collections.singleton(Utilities.toURI(file).toURL());
}
 
Example 4
Project: ultrasonic   File: ImageLoader.java   View Source Code Vote up 5 votes
public void startImageLoader()
{
	running.set(true);

	threads = Collections.synchronizedCollection(new ArrayList<Thread>(this.concurrency));

	for (int i = 0; i < this.concurrency; i++)
	{
		Thread thread = new Thread(this, String.format("ImageLoader_%d", i));
		threads.add(thread);
		thread.start();
	}
}
 
Example 5
Project: cactoos   File: SyncCollection.java   View Source Code Vote up 5 votes
/**
 * Ctor.
 * @param src An {@link Iterable}
 */
public SyncCollection(final Collection<T> src) {
    super(
        new SyncScalar<>(
            () -> {
                final Collection<T> temp = new LinkedList<>();
                temp.addAll(src);
                return Collections.synchronizedCollection(temp);
            }
        )
    );
}
 
Example 6
Project: scanning   File: AbstractRunnableDevice.java   View Source Code Vote up 5 votes
@Override
public void addPositionListener(IPositionListener l) {
	if (posListeners == null) {
		posListeners = Collections.synchronizedCollection(new LinkedHashSet<>());
	}
	posListeners.add(l);
}
 
Example 7
Project: AeroStory   File: GMServer.java   View Source Code Vote up 5 votes
public static void closeAllSessions() {
    try {//I CAN AND IT'S FREE BITCHES
        Collection<IoSession> sss = Collections.synchronizedCollection(outGame.values());
        synchronized (sss) {
            final Iterator<IoSession> outIt = sss.iterator();
            while (outIt.hasNext()) {
                outIt.next().close();
                outIt.remove();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 8
Project: scanning   File: MalcolmEventDelegate.java   View Source Code Vote up 4 votes
public void addMalcolmListener(IMalcolmListener<MalcolmEventBean> l) {
	if (listeners==null) listeners = Collections.synchronizedCollection(new LinkedHashSet<IMalcolmListener<MalcolmEventBean>>());
	listeners.add(l);
}
 
Example 9
Project: scanning   File: AbstractRunnableDevice.java   View Source Code Vote up 4 votes
@Override
public void addRunListener(IRunListener l) {
	if (rlisteners==null) rlisteners = Collections.synchronizedCollection(new LinkedHashSet<>());
	rlisteners.add(l);
}
 
Example 10
Project: jdk8u-jdk   File: java_util_Collections_SynchronizedCollection.java   View Source Code Vote up 4 votes
protected Collection<String> getObject() {
    List<String> list = Collections.singletonList("string");
    return Collections.synchronizedCollection(list);
}
 
Example 11
Project: jdk8u-jdk   File: java_util_Collections_SynchronizedCollection.java   View Source Code Vote up 4 votes
protected Collection<String> getAnotherObject() {
    List<String> list = Collections.emptyList();
    return Collections.synchronizedCollection(list);
}
 
Example 12
Project: openjdk-jdk10   File: java_util_Collections_SynchronizedCollection.java   View Source Code Vote up 4 votes
protected Collection<String> getObject() {
    List<String> list = Collections.singletonList("string");
    return Collections.synchronizedCollection(list);
}
 
Example 13
Project: openjdk-jdk10   File: java_util_Collections_SynchronizedCollection.java   View Source Code Vote up 4 votes
protected Collection<String> getAnotherObject() {
    List<String> list = Collections.emptyList();
    return Collections.synchronizedCollection(list);
}