callable

How to schedule a Callable to run on a specific time?

烈酒焚心 提交于 2020-01-01 17:50:09
问题 I need to run a callable at a specific time of day. One way to do it is to calculate the timediff between now and the desired time , and to use the executor.scheduleAtFixedRate . Have a better idea? executor.scheduleAtFixedRate(command, TIMEDIFF(now,run_time), period, TimeUnit.SECONDS)) 回答1: For this kind of thing, just go ahead and install Quartz. EJB has some support for this kind of thing but really you just want Quartz for scheduled tasks. That being said, if you insist on doing it

java Callable FutureTask Excecuter: How to listen to finished task

瘦欲@ 提交于 2019-12-30 03:19:11
问题 I'm quite new to executer services. Liked doing everything myself, but I think it's time to trust these services. I want to hand by Executer a Runnable . The executer wraps that in a FutureTask and hands it back to me. Now I call poll the done() method. But I would like to be notified when then done() method would return true. There is a get() method that blocks until the Runnable has finished, but then I would need a extra thread for every job, just to see when it's finished. Can I hand my

Java : How to return intermediate results from a Thread

。_饼干妹妹 提交于 2019-12-23 09:37:21
问题 Using Java 7 I am trying to build a watcher that watches a data store (some collection type) and then will return certain items from it at certain points. In this case they are time stamps, when a timestamp passes the current time I want it to be returned to the starting thread. Please see code below. @Override public void run() { while (!data.isEmpty()) { for (LocalTime dataTime : data) { if (new LocalTime().isAfter(dataTime)) { // return a result but continue running } } } } I have read

How to better use ExecutorService in multithreading environment?

心已入冬 提交于 2019-12-22 03:51:37
问题 I need to make a library in which I will have synchronous and asynchronous methods in it. executeSynchronous() - waits until I have a result, returns the result. executeAsynchronous() - returns a Future immediately which can be processed after other things are done, if needed. Core Logic of my Library The customer will use our library and they will call it by passing DataKey builder object. We will then construct a URL by using that DataKey object and make a HTTP client call to that URL by

What is a callable object in C++?

天涯浪子 提交于 2019-12-20 18:31:28
问题 I'm currently studying boost threads. And I came across that the thread class has a constructor that accepts callable objects. What are callable objects? class CallableClass { private: // Number of iterations int m_iterations; public: // Default constructor CallableClass() { m_iterations=10; } // Constructor with number of iterations CallableClass(int iterations) { m_iterations=iterations; } // Copy constructor CallableClass(const CallableClass& source) { m_iterations=source.m_iterations; } /

What happens to a BufferedReader that doesn't get closed within a callable.call?

爷,独闯天下 提交于 2019-12-20 13:06:00
问题 I have three questions. To explain, I was reviewing someone's code, and noticed BufferedReader s sometimes aren't being closed. Usually, Eclipse gives a warning that this is a potential memory leak (and I fix it). However, within a Callable inner class, there is no warning. class outerClass { ... public void someMethod() { Future<Integer> future = outputThreadPool.submit(new innerClass(this.myProcess.getInputStream(), threadName)); ... } class innerClass implements Callable<Integer> { private

What happens to a BufferedReader that doesn't get closed within a callable.call?

空扰寡人 提交于 2019-12-20 13:05:11
问题 I have three questions. To explain, I was reviewing someone's code, and noticed BufferedReader s sometimes aren't being closed. Usually, Eclipse gives a warning that this is a potential memory leak (and I fix it). However, within a Callable inner class, there is no warning. class outerClass { ... public void someMethod() { Future<Integer> future = outputThreadPool.submit(new innerClass(this.myProcess.getInputStream(), threadName)); ... } class innerClass implements Callable<Integer> { private

How to get foreign key values with getattr from models

吃可爱长大的小学妹 提交于 2019-12-20 10:43:51
问题 i have a model Project and i am getting the attributes of that with the following instr attr = getattr(project, 'id', None) project is the instance, id is the field and None is the default return type. my question is what if i want to get the F.K keys with this? Get customer name project.customer.name How to get customer name with the above condition? Already Tried if callable(attr): context[node][field] = '%s' % attr() Current Code context = {'project': {}} fields = ('id', 'name', 'category'

line = line.strip() TypeError: 'NoneType' object is not callable

倖福魔咒の 提交于 2019-12-20 07:06:33
问题 I am trying to find all num's in a list from an html using beautifulsoup : import urllib from BeautifulSoup import * import re line = None url = raw_input('Enter - ') html = urllib.urlopen(url).read() soup = BeautifulSoup(html) # Retrieve all of the anchor tags tags = soup('span') for line in tags: line = line.strip() numlist = re.findall('[0-9]+' , tags) print numlist` I'm getting a traceback: Traceback (most recent call last): File "C:\Documents and Settings\mea388\Desktop\PythonSchool\new

Why set the interrupt bit in a Callable

眉间皱痕 提交于 2019-12-20 05:59:05
问题 So, this resource (http://www.ibm.com/developerworks/java/library/j-jtp05236/index.html) suggest to set the interrupt bit in a Thread when that Thread does not deal with the interrupt itself, " so that code higher up on the call stack can learn of the interruption and respond to it if it wants to ." Let's say I'm using an ExecutorService to run something in a different Thread. I construct a Callable and pass this Callable into ExecutorService.submit(), which returns a Future. If the Callable