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
4
votes
1 answer

why increment of newFixedThreadPool result in poor performance?

I'm trying to change the execution of a report and have it done in concurrency. In a 'serail mode' the execution test takes 30 seconds and when using a concurrent mode I get 27 seconds (consider that few steps must be taken in serial I'm ok with the…
adhg
  • 10,437
  • 12
  • 58
  • 94
3
votes
2 answers

Java: ExecutorService with Callables: invokeAll() and future.get() - results in correct order?

Im using the ExecutorService in Java to invoke Threads with invokeAll(). After, I get the result set with future.get(). Its really important that I receive the results in the same order I created the threads. Here is a snippet: try { final List…
nano7
  • 2,455
  • 7
  • 35
  • 52
3
votes
2 answers

Design for a multi-threaded REST API client

I am working on a program that receives search requests for a topic, makes API calls to the New York Times API to fetch articles related to the topic, and then to the Twitter API to fetch tweets mentioning the articles and finally processes the…
gofeddy
  • 579
  • 8
  • 20
3
votes
3 answers

Is possible to control the amount of time that each thread executes in Java?

I want to control the amount of time that each thread uses. One thread does some processing and another processes data in the database, but the insertion is slower than processing because of the amount of generated data. I want to give more…
Renato Dinhani
  • 35,057
  • 55
  • 139
  • 199
3
votes
1 answer

Delphi: Using generics to accept any "callable" (e.g. procedure, procedure of object, lambda)

In C++ duck typing there is the concept of a callable, e.g. a symbol that can be called like a function. I'd like to emulate this with Delphi generics. I have a problem where I need a procedure that can accept either a normal procedure, a class…
jpo234
  • 419
  • 3
  • 9
3
votes
1 answer

Dataclass and Callable Initialization Problem via Classmethods

I found this weird behaviour where I don't know if I am the problem or if this is a python / dataclass / callable bug. Here is a minimal working example from dataclasses import dataclass from typing import Callable import numpy as np def…
Maikefer
  • 570
  • 1
  • 8
  • 21
3
votes
1 answer

Program won't exit in using Callable and Future

IDE: IntelliJ JDK: Java 11 While was testing a sample code from lecture, I have found something really weird that my program just won't stop, even though there aren't any loop! import java.util.concurrent.Callable; public class FindMaxTask…
co_lin
  • 125
  • 7
3
votes
1 answer

What is the notation for a callable instance parameter?

I am trying to find the most elegant way to help IntelliSense catch the expected set of parameters for the callables. Consider the following piece of code: class Box: def __init__(self, f: callable) -> None: self.f: callable = f def…
Ruben Kazumov
  • 3,803
  • 2
  • 26
  • 39
3
votes
4 answers

C++11 variadic templates calling a function inside a class

I'm learning variadic templates in C++11. How can I call test.finder as a functional argument of test.var_finder? #include #include class c_test { public: double finder(double a, double b = 0) { …
Medical physicist
  • 2,510
  • 4
  • 34
  • 51
3
votes
3 answers

User input with a timeout in Java

I'm trying to build a Command Line Interface with this functionality: if the user takes more than 15 seconds to insert an input (an Integer in this case), the function makes a default choice (0). The code below is what I wrote so far and it works…
anonymflaco
  • 158
  • 1
  • 10
3
votes
2 answers

Returning value from runInTransaction() In Android Room database

There is not much documentation to understand how exactly does runInTransaction() method works. While executing multiple operations on different DAO's if no value is to be returned I could use runInTransaction(Runnable body) OR…
user2234
  • 1,282
  • 1
  • 21
  • 44
3
votes
1 answer

How to cache closures in php

I want to cache an array which has also closures. I've tried with: serialize() - can't serialize closures json_encode() - replaces closure with empty value base64_encode() - doesn't accept arrays What else to do for caching array containing also…
3
votes
2 answers

boost multiple calls to class method

In boost::thread is it possible to call a class method with out making the class callable and implementing the void operator()() as in just call the class method for(int i=0;i<5;i++) boost::thread worker(myclass.myfunc,i,param2); I get an…
h1vpdata
  • 331
  • 2
  • 15
3
votes
2 answers

How can you tell when a Future object is done with its task?

I'm using Java 8. I was wondering how you can tell when a Future object is done with its task. I tried understanding it by writing the below Callable c = new Callable() { @Override public Long call() throws…
Dave
  • 15,639
  • 133
  • 442
  • 830
3
votes
1 answer

How to execute function if class instance is passed?

I currently have a TestClass that is callable. The callable executes a function that raises an exception if any attribute is equal to None. The purpose of defining it to be callable is so when TestClass instance is passed to another function or…
tyleax
  • 1,556
  • 2
  • 17
  • 45