List of usage examples for java.util Collections synchronizedList
public static <T> List<T> synchronizedList(List<T> list)
From source file:org.jspresso.framework.application.AbstractController.java
/** * Instantiates a new Abstract controller. *//*from ww w .ja v a 2 s.c om*/ protected AbstractController() { delayedActions = Collections.synchronizedList(new ArrayList<Map.Entry<IAction, Map<String, Object>>>()); }
From source file:com.googlecode.psiprobe.model.stats.StatsCollection.java
public synchronized List newStats(String name, int maxElements) { List stats = Collections.synchronizedList(new ArrayList(maxElements)); statsData.put(name, stats);//from w w w. j a va2s . c om return stats; }
From source file:org.jcf.GraphicObjectHandlerImpl.java
/** * ctor to use for a given room and nikname * @param nikName room unique nikname //from w w w . ja v a2s .co m * @param room room name */ GraphicObjectHandlerImpl(String nikName, String room) { Assert.notNull(nikName); Assert.notNull(room); this.room = room; this.nikName = nikName; objects = Collections.synchronizedMap(new HashMap<Id, GraphicObject>()); listener = Collections.synchronizedList(new ArrayList<GraphicObjectEventListener>()); threadLocalGraphicalMessage = new ThreadLocal<GraphicMessage>(); }
From source file:edu.sabanciuniv.sentilab.sare.models.setcover.DocumentSetCover.java
private Pair<List<SetCoverDocument>, List<SetCoverDocument>> splitByCoverage(double weightCoverage) { List<SetCoverDocument> covered = Lists.newArrayList(); List<SetCoverDocument> uncovered = Lists.newArrayList(); List<SetCoverDocument> setCoverDocuments = Collections .synchronizedList(Lists.newArrayList(this.getAllDocuments())); double totalWeight = this.getTotalWeight(); double accumulatedWeight = 0; // sort set cover. Iterator<SetCoverDocument> iterator = Ordering.from(new Comparator<SetCoverDocument>() { @Override/*from w ww.j a v a2 s. c o m*/ public int compare(SetCoverDocument o1, SetCoverDocument o2) { return (int) ((o2.getWeight() - o1.getWeight()) * 100); } }).immutableSortedCopy(setCoverDocuments).iterator(); // get all the useful ones. while (iterator.hasNext()) { if (accumulatedWeight >= weightCoverage * totalWeight) { break; } SetCoverDocument document = iterator.next(); accumulatedWeight += document.getWeight(); covered.add(document); } while (iterator.hasNext()) { uncovered.add(iterator.next()); } return new ImmutablePair<List<SetCoverDocument>, List<SetCoverDocument>>(covered, uncovered); }
From source file:ubc.pavlab.aspiredb.server.controller.SignupControllerTest.java
@Test public void testSignup() throws Exception { int numThreads = 10; // too high and we run out of connections, which is not what we're testing. final int numsignupsperthread = 10; final Random random = new Random(); final AtomicInteger c = new AtomicInteger(0); final AtomicBoolean failed = new AtomicBoolean(false); Collection<Thread> threads = new HashSet<Thread>(); final Collection<String> unames = Collections.synchronizedList(new ArrayList<String>()); for (int i = 0; i < numThreads; i++) { Thread k = new Thread(new Runnable() { @Override//from ww w . j a va2 s . co m public void run() { try { for (int j = 0; j < numsignupsperthread; j++) { MockHttpServletRequest req = null; Thread.sleep(random.nextInt(50)); req = new MockHttpServletRequest("POST", "/signup.html"); final String uname = RandomStringUtils.randomAlphabetic(10); synchronized (unames) { unames.add(uname); } // log.info( "Signingup: " + uname + " (" + c.get() + ")" ); String password = RandomStringUtils.randomAlphabetic(40); req.addParameter("password", password); req.addParameter("passwordConfirm", password); req.addParameter("username", uname); String email = "foo@" + RandomStringUtils.randomAlphabetic(10) + ".edu"; req.addParameter("email", email); suc.signup(req, new MockHttpServletResponse()); // Cleanup // userService.delete( userService.findByUserName( uname ) ); c.incrementAndGet(); } } catch (Exception e) { failed.set(true); log.error("!!!!!!!!!!!!!!!!!!!!!! FAILED: " + e.getMessage()); log.debug(e, e); throw new RuntimeException(e); } log.debug("Thread done."); } }); threads.add(k); k.start(); } int waits = 0; int maxWaits = 30; int expectedEventCount = numThreads * numsignupsperthread; while (c.get() < expectedEventCount && !failed.get()) { try { Thread.sleep(8000); } catch (InterruptedException e) { e.printStackTrace(); } log.info("Waiting ... C=" + +c.get()); if (++waits > maxWaits) { for (Thread t : threads) { if (t.isAlive()) t.interrupt(); } fail("Multithreaded failure: timed out."); } } // cleanup for (String uname : unames) { userService.delete(userService.findByUserName(uname)); } log.debug(" &&&&& DONE &&&&&"); for (Thread thread : threads) { if (thread.isAlive()) thread.interrupt(); } if (failed.get() || c.get() != expectedEventCount) { fail("Multithreaded loading failure: check logs for failure to recover from deadlock?"); } else { log.info("TORTURE TEST PASSED!"); } }
From source file:eu.luminis.httpjca.HttpManagedConnection.java
/** * Default constructor//from ww w . ja v a2 s . co m * @param mcf mcf */ public HttpManagedConnection(HttpManagedConnectionFactory mcf) throws ResourceException { this.mcf = mcf; this.logwriter = null; this.listeners = Collections.synchronizedList(new ArrayList<ConnectionEventListener>(1)); this.connection = null; this.socket = null; // TODO: Initialize me }
From source file:org.charleech.primefaces.eval.ui.table.lazy.LazyMyDataDataModel.java
@Override public List<MyData> load(final int first, final int pageSize, final String sortField, final SortOrder sortOrder, final Map<String, String> filters) { List<MyData> datas = null; boolean match = false; int dataSize = -1; try {// w w w .j a v a 2s.c om datas = Collections.synchronizedList(new ArrayList<MyData>()); for (final MyData data : this.datasource) { match = this.determine(data, filters); if (match) { datas.add(data); } } //sort if (sortField != null) { Collections.sort(datas, new LazySorter(sortField, sortOrder)); } //rowCount dataSize = datas.size(); this.setRowCount(datas.size()); //paginate if (dataSize > pageSize) { try { return datas.subList(first, first + pageSize); } catch (final IndexOutOfBoundsException e) { return datas.subList(first, first + (dataSize % pageSize)); } } else { return datas; } } finally { datas = null; } }
From source file:org.kuali.rice.krad.util.MessageMap.java
public MessageMap() { errorPath = Collections.synchronizedList(new ArrayList<String>()); errorMessages = Collections.synchronizedMap(new LinkedHashMap<String, List<ErrorMessage>>()); warningMessages = Collections.synchronizedMap(new LinkedHashMap<String, List<ErrorMessage>>()); infoMessages = Collections.synchronizedMap(new LinkedHashMap<String, List<ErrorMessage>>()); growlMessages = Collections.synchronizedList(new AutoPopulatingList<GrowlMessage>(GrowlMessage.class)); }
From source file:org.agnitas.beans.impl.ImportProfileImpl.java
public ImportProfileImpl() { genderMapping = Collections.synchronizedMap(new HashMap<String, Integer>()); columnMapping = Collections.synchronizedList(new ArrayList<ColumnMapping>()); keyColumns = new ArrayList<String>(); }
From source file:epgtools.dumpepgfromts.subtool.filelistmaker.FileSeeker.java
/** * ???????/*w w w. j a v a 2 s . c o m*/ * * @return ?????? */ public synchronized List<File> seek() { List<File> list = Collections.synchronizedList(new ArrayList<File>()); Collection<File> files = FileUtils.listFiles(this.SourceDir, this.fileType, this.dirf); list.addAll(files); return Collections.unmodifiableList(list); }