Questions tagged [callable]

A task that returns a result and may throw an exception.

The Callable interface is similar to Runnable, in that both are designed for classes whose instances are potentially executed by another thread. A Runnable, however, does not return a result and cannot throw a checked exception.

759 questions
3
votes
3 answers

Use php callable to call constructor

I am trying to call a class' constructor through a callable, so I had the following code: $callable = array('Foo', '__construct'); However calling this will throw the following error: Fatal error: Non-static method Foo::__construct() cannot be…
Choraimy
  • 166
  • 1
  • 11
3
votes
1 answer

How to cancel (or just interrupt) a scala.concurrent.Future?

I have a Java library that performs long running blocking operations. The library is designed to respond to user cancellation requests. The library integration point is the Callable interface. I need to integrate this library into my application…
axiopisty
  • 4,972
  • 8
  • 44
  • 73
3
votes
3 answers

Android Callable

How to implement Callable to return boolean and do something ? I need use external Thread to connect to FTP server, I can't do this in main activity and I need return value to know it's connected or not; [MainActivity] public class doSomething…
Nerus
  • 167
  • 1
  • 2
  • 13
3
votes
3 answers

Do callable executes sequentially?

Whenever i run my program implementing callable, i get the output in a sequential form. Like, here is my program : package com.handson; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; import…
Prateek
  • 12,014
  • 12
  • 60
  • 81
3
votes
1 answer

Why am I getting a NullPointerException when fetching values from Futures?

I'm using and ExecutorService to concurrently run some Callables. Here's a simplified version of my code: ArrayList objResults = new ArrayList(); ExecutorService esrExecutor =…
Mridang Agarwalla
  • 43,201
  • 71
  • 221
  • 382
3
votes
1 answer

Do spurious wakeups affect Future.get()?

Is Future.get( timeout, unit ) susceptible to the same type of spurious wakeup as documented for Object.wait() and Condition.await() in Javadoc? someType result; Future future = executor.submit( new callableTask() ); result = future.get(…
Ed K
  • 189
  • 2
  • 9
3
votes
1 answer

How to get a string value from a thread at fixed intervals while able to pause/resume?

I have made a small swing application for my personal use. This app connects to internet, retrieves a text file, displays its contents in a jTextArea and saves the text file locally (in my hardisk). So far so good. Now I want to receive this text…
mzeeshan
  • 33
  • 4
3
votes
3 answers

Using callable to pass two parameters and returning an array of parameters

I have to pass two strings to a thread, which will return an array containing both of them, and I must use callable. Here's what I have so far: public class toArray implements Callable { private String string1 string2; public toArray…
Ryan
  • 269
  • 4
  • 5
  • 12
3
votes
3 answers

Multithreaded file processing and reporting

I have an application that processes data stored in a number of files from an input directory and then produces some output depending on that data. So far, the application works in a sequential basis, i.e. it launches a "manager" thread that Reads…
PNS
  • 19,295
  • 32
  • 96
  • 143
3
votes
1 answer

How to send a function to a remote Pyro object

I am trying to set up some code using Pyro to process python code functions on a remote host and get results back. After starting the name server, i would execute this code on the remote host (actually still on localhost): import Pyro4 class…
Davide
  • 1,415
  • 2
  • 11
  • 13
2
votes
3 answers

Java: ExecutorService with Callables: Timeout: future.get() leads to direct break of program

I use the ExecutorService in Java and I noticed a behaviour I dont understand. I use Callable and when I invoke my threads (classes that implement Callable) I set a timeout. Then I wait for the result with future.get() and after I wanted to check…
nano7
  • 2,455
  • 7
  • 35
  • 52
2
votes
2 answers

Polymorphism with callables in Python

I have an interface class called iResource, and a number of subclasses, each of which implement the "request" method. The request functions use socket I/O to other machines, so it makes sense to run them asynchronously, so those other machines can…
xanderflood
  • 826
  • 2
  • 12
  • 22
2
votes
1 answer

Why the exception is not being thrown?

I have this simple piece of code: @Override public Object call() throws Exception { try (Connection conn = ConnectionPool.getConnection()) { pageDAO = new PageDAO(conn); linkDAO = new LinkDAO(conn); loopInsertion(); …
Renato Dinhani
  • 35,057
  • 55
  • 139
  • 199
2
votes
1 answer

How to interface this DFS code with a Boost Graph DFS?

Background I have defined formatting operations on trees that work pretty well when they are used a pre/in/post order operators with the following structure and DFS definition (it works also on k-ary trees): struct Node { Node *parent = nullptr; …
WaterFox
  • 850
  • 6
  • 18
2
votes
3 answers

chaining callables in C++

I come from the python world where I could define a chain of operations and call them in a for loop: class AddOne: def __call__(self, x, **common_kwargs): return x+1 class Stringify: def __call__(self, x, **common_kwargs): …
Jav
  • 1,445
  • 1
  • 18
  • 47