当前位置: 首页>>代码示例>>Java>>正文


Java Collections.synchronizedList方法代码示例

本文整理汇总了Java中java.util.Collections.synchronizedList方法的典型用法代码示例。如果您正苦于以下问题:Java Collections.synchronizedList方法的具体用法?Java Collections.synchronizedList怎么用?Java Collections.synchronizedList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.Collections的用法示例。


在下文中一共展示了Collections.synchronizedList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: stop

import java.util.Collections; //导入方法依赖的package包/类
public void stop() {
	if (logger.isLoggingEnabled(LogLevels.TRACE_DEBUG)) {
		logger.logDebug("stopStack -- stoppping the stack");
		logger.logStackTrace();
	}
	this.stopStack();
	if(super.sipMessageValve != null) 
		super.sipMessageValve.destroy();
	if(super.sipEventInterceptor != null) 
		super.sipEventInterceptor.destroy();
	this.sipProviders = Collections.synchronizedList(new LinkedList<SipProviderImpl>());
	this.listeningPoints = new Hashtable<String, ListeningPointImpl>();
	/*
	 * Check for presence of an event scanner ( may happen if stack is
	 * stopped before listener is attached ).
	 */
	if (this.eventScanner != null)
		this.eventScanner.forceStop();
	this.eventScanner = null;
	PostParseExecutorServices.shutdownThreadpool();

}
 
开发者ID:YunlongYang,项目名称:LightSIP,代码行数:23,代码来源:SipStackImpl.java

示例2: unresizable

import java.util.Collections; //导入方法依赖的package包/类
/**
 * Lists that don't allow resizing, but allow setting values
 */
@DataProvider
public static Object[][] unresizable() {
    final List<Integer> c1 = Arrays.asList(42);
    final List<Integer> c9 = Arrays.asList(40, 41, 42, 43, 44, 45, -1,
            Integer.MIN_VALUE, 1000500);

    Object[][] l1 = unsettable();
    Object[][] l2 = {
        {c1, 0, 1},
        {c1.subList(0, 1), 0, 1},
        {Collections.checkedList(c1, Integer.class), 0, 1},
        {Collections.synchronizedList(c1), 0, 1},
        {c9, 0, 4},
        {c9, 4, 6},
        {c9.subList(1, 8), 1, 4},
        {c9.subList(1, 8), 0, 7},
        {Collections.checkedList(c9, Integer.class), 3, 6},
        {Collections.synchronizedList(c9), 3, 5},
    };
    Object[][] res = Arrays.copyOf(l1, l1.length + l2.length);
    System.arraycopy(l2, 0, res, l1.length, l2.length);
    return res;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:SubList.java

示例3: EventRequestManagerImpl

import java.util.Collections; //导入方法依赖的package包/类
/**
 * Constructor.
 */
EventRequestManagerImpl(VirtualMachine vm) {
    super(vm);
    java.lang.reflect.Field[] ekinds =
        JDWP.EventKind.class.getDeclaredFields();
    int highest = 0;
    for (int i = 0; i < ekinds.length; ++i) {
        int val;
        try {
            val = ekinds[i].getInt(null);
        } catch (IllegalAccessException exc) {
            throw new RuntimeException("Got: " + exc);
        }
        if (val > highest) {
            highest = val;
        }
    }
    requestLists = new List[highest+1];
    for (int i=0; i <= highest; i++) {
        requestLists[i] = Collections.synchronizedList(new ArrayList<>());
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:EventRequestManagerImpl.java

示例4: reInitialize

import java.util.Collections; //导入方法依赖的package包/类
/**
 * ReInitialize the stack instance.
 */
private void reInitialize() {
	super.reInit();
	this.eventScanner = new EventScanner(this);
	this.listeningPoints = new Hashtable<String, ListeningPointImpl>();
	this.sipProviders = Collections.synchronizedList(new LinkedList<SipProviderImpl>());
	this.sipListener = null;
	if(!getTimer().isStarted()) {			
		String defaultTimerName = configurationProperties.getProperty("gov.nist.javax.sip.TIMER_CLASS_NAME",DefaultSipTimer.class.getName());
		try {				
			setTimer((SipTimer)Class.forName(defaultTimerName).newInstance());
			getTimer().start(this, configurationProperties);
			if (getThreadAuditor().isEnabled()) {
	            // Start monitoring the timer thread
	            getTimer().schedule(new PingTimer(null), 0);
	        }
		} catch (Exception e) {
			logger
				.logError(
						"Bad configuration value for gov.nist.javax.sip.TIMER_CLASS_NAME", e);			
		}
	}
}
 
开发者ID:YunlongYang,项目名称:LightSIP,代码行数:26,代码来源:SipStackImpl.java

示例5: testForEach

import java.util.Collections; //导入方法依赖的package包/类
@Test(dataProvider = "StreamTestData<Integer>", dataProviderClass = StreamTestDataProvider.class)
public void testForEach(String name, TestData.OfRef<Integer> data) {
    Function<Stream<Integer>, List<Integer>> terminalFunc = s -> {
        List<Integer> l = Collections.synchronizedList(new ArrayList<>());
        s.forEach(l::add);
        return l;
    };

    // Test head
    withData(data).
            terminal(terminalFunc).
            resultAsserter(resultAsserter()).
            exercise();

    // Test multiple stages
    withData(data).
            terminal(s -> s.map(LambdaTestHelpers.identity()), terminalFunc).
            resultAsserter(resultAsserter()).
            exercise();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:ForEachOpTest.java

示例6: MyTableModel

import java.util.Collections; //导入方法依赖的package包/类
/**
 * Creates a new MyTableModel.
 */
public MyTableModel(SwingGui debugGui) {
    this.debugGui = debugGui;
    expressions = Collections.synchronizedList(new ArrayList<String>());
    values = Collections.synchronizedList(new ArrayList<String>());
    expressions.add("");
    values.add("");
}
 
开发者ID:middle2tw,项目名称:whackpad,代码行数:11,代码来源:SwingGui.java

示例7: testCommit

import java.util.Collections; //导入方法依赖的package包/类
@Test(dataProvider = TEST)
public void testCommit(
        List<List<Object>> changes,
        long deadTransaction,
        List<Integer> expectedCommitted,
        List<Map.Entry<Integer, Integer>> expectedBefore
) {
    ByteBuffer buffer = ByteBuffer.allocate(0);

    List<Long> txIdsToCommit = LongStream.range(0, changes.size()).boxed().collect(toList());
    Map<Long, TransactionData> input = new HashMap<>(changes.size());
    for (int i = 0; i < changes.size(); i++) {

        List<Map.Entry<String, List>> list = singletonList(pair(CACHE_NAME, changes.get(i)));
        TransactionData data = new TransactionData(new TransactionScope((long) i, list), buffer, new TopicPartition("topic", 0), 0L);
        input.put((long) i, data);
    }

    CommitServitor servitor = mock(CommitServitor.class);
    List<Long> actual = Collections.synchronizedList(new ArrayList<>());
    doAnswer(mock -> !mock.getArguments()[0].equals(deadTransaction) && actual.add((Long) mock.getArguments()[0]))
            .when(servitor)
            .commit(anyLong(), anyMap());

    ParallelCommitStrategy strategy = new ParallelCommitStrategy(servitor, "localGridName");
    List<Long> actualCommitted = strategy.commit(txIdsToCommit, input);

    Assert.assertEquals(actualCommitted, expectedCommitted.stream().map(Integer::longValue).collect(toList()));

    checkOrder(expectedBefore, actual);
}
 
开发者ID:epam,项目名称:Lagerta,代码行数:32,代码来源:ParallelCommitStrategyUnitTest.java

示例8: JCAManagedConnection

import java.util.Collections; //导入方法依赖的package包/类
public JCAManagedConnection(JCAManagedConnectionFactory fact) {
  this.factory = fact;
  this.listeners = Collections
      .<ConnectionEventListener>synchronizedList(new ArrayList<ConnectionEventListener>());
  this.localTran = new JCALocalTransaction();
  this.connections =
      Collections.<GFConnectionImpl>synchronizedSet(new HashSet<GFConnectionImpl>());
}
 
开发者ID:ampool,项目名称:monarch,代码行数:9,代码来源:JCAManagedConnection.java

示例9: DynamoDBAnnouncementWatcher

import java.util.Collections; //导入方法依赖的package包/类
public DynamoDBAnnouncementWatcher(AWSCredentials credentials, String tableName, String blobNamespace) {
    this.dynamoDB = new DynamoDB(new AmazonDynamoDBClient(credentials));
    this.tableName = tableName;
    this.blobNamespace = blobNamespace;
    this.subscribedConsumers = Collections.synchronizedList(new ArrayList<HollowConsumer>());
    
    this.latestVersion = readLatestVersion();
    
    setupPollingThread();
}
 
开发者ID:Netflix,项目名称:hollow-reference-implementation,代码行数:11,代码来源:DynamoDBAnnouncementWatcher.java

示例10: ScreenDeviceModule

import java.util.Collections; //导入方法依赖的package包/类
public ScreenDeviceModule(IWebView webView, IMessageSender messageSender) {
    super(ApiConstants.NAMESPACE, messageSender);
    this.webView = webView;
    webView.addWebViewListener(new IWebView.IWebViewListener() {
        @Override
        public void onLinkClicked(String url) {
            sendLinkClickedEvent(url);
        }
    });
    this.listeners = Collections.synchronizedList(new ArrayList<IRenderVoiceInputTextListener>());
    renderListeners = new ArrayList<>();
}
 
开发者ID:dueros,项目名称:dcs-sdk-java,代码行数:13,代码来源:ScreenDeviceModule.java

示例11: WakeUpImpl

import java.util.Collections; //导入方法依赖的package包/类
public WakeUpImpl(Context context, LinkedBlockingDeque<byte[]> linkedBlockingDeque) {
    this.linkedBlockingDeque = linkedBlockingDeque;
    this.context = context.getApplicationContext();
    this.wakeUpNative = new WakeUpNative();
    this.wakeUpListeners = Collections.synchronizedList(new LinkedList<IWakeUpListener>());
    this.initWakeUp();
}
 
开发者ID:dueros,项目名称:dcs-sdk-java,代码行数:8,代码来源:WakeUpImpl.java

示例12: testQueryDocuments_filterFetchedResults

import java.util.Collections; //导入方法依赖的package包/类
@Test
public void testQueryDocuments_filterFetchedResults() throws Exception {
    // queries for documents and filter out the fetched results

    int requestPageSize = 3;
    FeedOptions options = new FeedOptions();
    options.setPageSize(requestPageSize);

    Func1<Document, Boolean> isPrimeNumber = new Func1<Document, Boolean>() {

        @Override
        public Boolean call(Document doc) {
            int n = doc.getInt("counter");
            if (n <= 1) return false;
            for(int i = 2; 2*i < n; i++) {
                if(n % i == 0)
                    return false;
            }
            return true;
        }
    };
    
    List<Document> resultList = Collections.synchronizedList(new ArrayList<Document>());
    
    asyncClient
        .queryDocuments(createdCollection.getSelfLink(), "SELECT * FROM root", options)
        .map(FeedResponsePage::getResults)              // map the page to the list of documents
        .concatMap(Observable::from)                    // flatten the observable<list<document>> to observable<document>
        .filter(isPrimeNumber)                          // filter documents using isPrimeNumber predicate
        .subscribe(doc -> resultList.add(doc));         // collect the results
    
    Thread.sleep(4000);
    
    int expectedNumberOfPrimes = 0;
    // find all the documents with prime number counter
    for(int i = 0; i < numberOfDocuments; i++) {
        boolean isPrime = true;
        if (i <= 1) isPrime = false;
        for(int j = 2; 2*j < i; j++) {
            if(i % j == 0) {
                isPrime = false;
                break;
            }
        }

        if (isPrime) {
            expectedNumberOfPrimes++;
        }
    }
    
    // assert that we only collected what's expected
    assertThat(resultList, hasSize(expectedNumberOfPrimes));
}
 
开发者ID:Azure,项目名称:azure-documentdb-rxjava,代码行数:54,代码来源:DocumentQueryAsyncAPITest.java

示例13: periodicallyPublishLastNInfo

import java.util.Collections; //导入方法依赖的package包/类
/**
 * Periodically publish the lastN on a stream.
 * @param stream tuples to 
 * @param count sliding window size "lastN"
 * @param nSec publish frequency
 * @param event sensor's publish event label
 */
private void periodicallyPublishLastNInfo(TStream<JsonObject> stream, 
        int count, int nSec, String event) {

    // Demonstrate periodic publishing of a sliding window if
    // something changed since it was last published.

    // Maintain a sliding window of the last N tuples.
    // TODO today, windows don't provide "anytime" access to their collection
    // so maintain our own current copy of the collection that we can
    // access it when needed.
    // 
    List<JsonObject> lastN = Collections.synchronizedList(new ArrayList<>());
    stream.last(count, JsonTuples.keyFn())
        .aggregate((samples, key) -> samples)
        .tag(event+".lastN")
        .sink(samples -> {
                // Capture the new list/window.  
                synchronized(lastN) {
                    lastN.clear();
                    lastN.addAll(samples);
                }
            });

    // Publish the lastN (with trimmed down info) every nSec seconds
    // if anything changed since the last publish.
    TStream<JsonObject> periodicLastN = 
            t.poll(() -> 1, nSec, TimeUnit.SECONDS).tag(event+".trigger")
            .filter(trigger -> !lastN.isEmpty()).tag(event+".changed")
            .map(trigger -> {
                synchronized(lastN) {
                    // create a single JsonObject with the list
                    // of reduced-content samples
                    JsonObject jo = new JsonObject();
                    jo.addProperty(KEY_ID, sensorId);
                    jo.addProperty(KEY_TS, System.currentTimeMillis());
                    jo.addProperty("window", count);
                    jo.addProperty("pubFreqSec", nSec);
                    JsonArray ja = new JsonArray();
                    jo.add("lastN", ja);
                    for (JsonObject j : lastN) {
                        JsonObject jo2 = new JsonObject();
                        ja.add(jo2);
                        jo2.add(KEY_TS, j.get(KEY_TS));
                        // reduce size: include only 2 significant digits
                        jo2.addProperty(KEY_READING, String.format("%.2f", 
                            JsonTuples.getStatistic(j, MEAN).getAsDouble()));
                    }
                    lastN.clear();
                    return jo;
                }
            })
            .tag(event);

    traceStream(periodicLastN, event);

    // Use a pressureReliever to prevent backpressure if the broker
    // can't be contacted.
    // TODO enhance MqttDevice with configurable reliever. 
    app.mqttDevice().events(
            PlumbingStreams.pressureReliever(periodicLastN, tuple -> 0, 30)
                .tag(event+".pressureRelieved"),
            app.sensorEventId(sensorId, event), QoS.FIRE_AND_FORGET);
}
 
开发者ID:osswangxining,项目名称:iot-edge-greengrass,代码行数:71,代码来源:Sensor1.java

示例14: writeStatsRequest

import java.util.Collections; //导入方法依赖的package包/类
@Override
public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest(
        OFStatsRequest<REPLY> request) {
    if (!isConnected())
        return Futures.immediateFailedFuture(new SwitchDisconnectedException(getDatapathId()));

    final DeliverableListenableFuture<List<REPLY>> future =
            new DeliverableListenableFuture<List<REPLY>>();

    Deliverable<REPLY> deliverable = new Deliverable<REPLY>() {
        private final List<REPLY> results = Collections
                .synchronizedList(new ArrayList<REPLY>());

        @Override
        public void deliver(REPLY reply) {
            results.add(reply);
            if (!reply.getFlags().contains(OFStatsReplyFlags.REPLY_MORE)) {
                // done
                future.deliver(results);
            }
        }

        @Override
        public void deliverError(Throwable cause) {
            future.deliverError(cause);
        }

        @Override
        public boolean isDone() {
            return future.isDone();
        }

        @Override
        public boolean cancel(boolean mayInterruptIfRunning) {
            return future.cancel(mayInterruptIfRunning);
        }
    };

    registerDeliverable(request.getXid(), deliverable);
    this.write(request);
    return future;
}
 
开发者ID:nsg-ethz,项目名称:iTAP-controller,代码行数:43,代码来源:OFConnection.java

示例15: DecomposedQueue

import java.util.Collections; //导入方法依赖的package包/类
public DecomposedQueue(int capacity, boolean allowConcurrentEventTypeProcessing) {
    this.capacity = capacity;
    this.allowConcurrentEventTypeProcessing = allowConcurrentEventTypeProcessing;

    entries = Collections.synchronizedList(new ArrayList<>(capacity));
}
 
开发者ID:softelnet,项目名称:sponge,代码行数:7,代码来源:DecomposedQueue.java


注:本文中的java.util.Collections.synchronizedList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。