queue

Thread safe limited size queue

杀马特。学长 韩版系。学妹 提交于 2019-12-11 13:24:28
问题 I'm trying to write a subj queue, but I get deadlocks and other multithreading problems. I want to use Interlocked.CompareExchange to avoid lock usage. But this code doesn't work as expected: it just wipe entire Queue. What am I doing wrong here? public class FixedSizedQueue<T> : IEnumerable<T> { readonly ConcurrentQueue<T> _queue = new ConcurrentQueue<T>(); public int Limit { get; set; } public FixedSizedQueue(int limit) { Limit = limit; } public void Enqueue(T obj) { _queue.Enqueue(obj); if

Measuring “busyness” of the event dispatching thread

允我心安 提交于 2019-12-11 11:18:32
问题 I would like to measure the "busyness" of my Event Dispatching Thread. One possible idea is to set up a background thread that does something like: while(true) { final long[] end = new long[1]; // Array to get stuff out from Runnable. long start = System.nanoTime(); EventQueue.invokeAndWait(new Runnable() { public void run() { end[0] = System.nanoTime(); } }); long queueTimeNs = end[0] - start; // Report the queue time somewhere. Thread.sleep(100); // Poll the EDT < 10 times/s. } The idea is

ZeroMQ individual subscriber queues

﹥>﹥吖頭↗ 提交于 2019-12-11 09:42:19
问题 I have a question about ZeroMQ PUB/SUB . Does the publisher create a separate queue for each individual subscriber or is there one queue for all subscribers (and hence limited by the slowest subscriber)? 回答1: Each connected subscriber gets its own queue. When a subscriber is slow, its own queue will fill up and then overflow (high water mark is by default 1,000), and its messages will get dropped. This won't affect other subscribers. 来源: https://stackoverflow.com/questions/16220679/zeromq

How to run a thread more than once in python

人盡茶涼 提交于 2019-12-11 09:39:34
问题 I am trying to run a thread more than once and keep getting an error: RuntimeError: threads can only be started once I have tried reading up multithreading and implementing it in my code without any luck. Here is the function I am threading: def receive(q): host = "" port = 13000 buf = 1024 addr = (host,port) Sock = socket(AF_INET, SOCK_DGRAM) Sock.bind(addr) (data, addr) = Sock.recvfrom(buf) q.put(data) Here is the code I want to run: q = Queue.Queue() r = threading.Thread(target=receive,

Iterate through a fileSystem without using Binary tree or recursion

不羁的心 提交于 2019-12-11 09:09:22
问题 I have seen to similar questions here on this topic but none really helped me grasp the steps to solve this. Given a queue, and a rootNode , how can I iterate through it? I understand first I have to enqueue the node I start with, but I am confused on how to implement the next() method. Also it has to be breadth-first traversal. for the next() method I have this: public File next(){ while(the peek() is a directory ("parent"){ use lists() to return the array of files iterate thru those and add

Stacking multiple AJAX requests on success (jQuery)

匆匆过客 提交于 2019-12-11 09:07:52
问题 I'm just testing a local application and wanted to make something like this: Click button, that's easy. Perform AJAX request and create a database table. Once the table is created, perform another series of AJAX requests and populate the table according to some parameters gotten from a series of select boxes. "Animate" the whole thing using a progress bar. Surprisingly, everything is working fine (apart the last point), but I'm getting some troubles. The table gets created and populated but,

show progress loader while asynchronously loading and processing csv files

江枫思渺然 提交于 2019-12-11 09:02:10
问题 My question is quite simple, but I'm having a difficult time figuring out how to go about solving it. As shown in the code below, I am loading 3 csv files and then processing them using queue.js. While this is happening, I want some type of progress indicator to be shown to the user. queue() .defer(d3.csv,"data/1.csv") .defer(d3.csv,"data/2.csv") .defer(d3.csv,"data/3.csv") .awaitAll(preprocessing); I have managed to get a progress bar to show up when the document is ready using JQuery.

Determine if a task has been deleted GAE Python

▼魔方 西西 提交于 2019-12-11 08:18:01
问题 I want to load up several tasks in the Task Queue (push) and then determine when the group of tasks I've added to the queue have been completed. I have the following code: task = taskqueue.add(url='/task') import time while not task.was_deleted: logging.info('not deleted yet') time.sleep(1) This loops indefinitely. I expected that once the task was processed and deleted the 'was_deleted' parameter would return True. But even when the task is deleted, 'was_deleted' continues to return false.

Java (String) - what does it do?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 08:08:34
问题 I was doing some past papers on my exam and I came accross this question : What does (String) do on line 5 and what is this type of expression called? Here is line 5 : String str = (String) D.dequeue (); My guess is that it's veryfing if the value we get from D.dequeue() is a String though I am not sure. 回答1: This is called Casting. The value returned by the Dequeue method is cast to a String type. Essentially this operation forces the value to take the type of String so that you can assign

Rails 3 and scheduling of repetitive tasks without cron

怎甘沉沦 提交于 2019-12-11 07:53:34
问题 I have a app and i am currently using delayed_job. I was wondering if there are any recommended gems that do scheduling of repetitive tasks. I want to schedule task that happen on a certain frequency to clean the database/sending emails/run other methods. I mite want to run some tasks every day or every hour. Is there any good ones out there that are fairly easy to setup and config which do not use CRON. 回答1: You can convert that repetitive work to rakes and call those rakes via cron. For