Questions tagged [runnable]
The Runnable interface defines a single method, run, meant to contain the code executed in the thread.
2,052
questions
0
votes
0
answers
17
views
How to keep the seek bar persistent even after back button is pressed and re opened player activity
i am trying to create a music app. the seek bar in the media player is not working if i pressed back button and reopen the activity again.
could anybody help me to solve this problem?
here is My play ...
0
votes
0
answers
28
views
Typing Animation Restarting Beyond Conditional Boundaries Issue
The problem is that if i click the button before a character increment animation completes, it restarts the animation from the beginning. However, once the animation reaches the last character, it ...
0
votes
1
answer
57
views
Can I implement Shedlock for the run method implemented by the runnable interface
I have a scheduler task created using Scheduled Future and Task scheduler. the scheduled task is basically a new class which implements runnable and used run method of the runnable interface. My doubt ...
1
vote
0
answers
24
views
NullPointerException on View Pager getCurrentItem
I am using viewpager for a carousel in my application. it works fine when the app open for the first time, but when coming back from another fragment am getting an error as NullPointerException, I ...
-2
votes
1
answer
71
views
Can we have a long process in a thread updates a progress bar? [closed]
I’m facing a problem with thread and interface.
In my example I have a long process. Along calculations I must stop and ask the user informations. I cannot do that before. So I have to open a window ...
-1
votes
1
answer
67
views
Create Runnable with "final" variable from the parent?
Create multiple new Runnable inside a loop ?
I want to create multiple new instances of Runnable that calls another method and passing the "i" parameter from the parent's loop.
I do not want ...
0
votes
0
answers
13
views
How can I check if a previously started app's background Runnable is still running?
How can I check when I start my app whether a runnable from a previously started app instance is running in the background? The runnable is there to send notifications at regular intervals. I tried it ...
0
votes
2
answers
358
views
Java - Execute multiple Runnables in parallel and trigger to timeout some of long running tasks?
I've a list of Runnable tasks (e.g. it contains 100 tasks, and each task takes randomly 1 - 10 seconds). The tasks must run in parallel and from the thread pool provided by ExecutorService (e.g. my ...
0
votes
1
answer
23
views
Runnable should start only one time
how can I prevent the runnable from being started a second time when the app is restarted? The runnable sends messages out at a certain interval.
I've been working with SharedPrefrences and it doesn'...
0
votes
0
answers
40
views
Deferred, rate limited Runnable execution
I'm writing an event handler that must trigger some downstream update process, which is currently done by dropping a Runnable instance into an ExecutorService (execute).
The challenge is: The event ...
0
votes
1
answer
101
views
How to show a circular loader during an API request in Android Studio
I am trying to show the Progress Bar component (circular, not horizontal) during a GET api request in Android Studio. I am running the API request on a different thread and I am setting the progress ...
0
votes
0
answers
30
views
How to draw real time linechart mpandroid from reading data from file and plotting continuously?
i am newbie in android,i have class names LedControl,i have to display realtime linechart in mpandroid. I have tried lot but all vain.but no linechart is drawing.Please Help with full code.
i have ...
1
vote
2
answers
67
views
Can i encapsulate the creation of similar threads into a method?
I'm writing a search function that is doing multiple API calls that i would like to execute asynchronous and collect their results. All my threads with their runnables look similar which made we ...
-1
votes
1
answer
202
views
Is "public static void main(String[] name)" the only way to make a runnable class?
The only clear commands of the main class for me are static, because you have to execute the method wihtout needing an object, void, because it has no return value and the String array name which you ...
0
votes
1
answer
45
views
How do I use the synchronized command correctly?
I'm making a game to memorise katakana. It plays like Whack-a-mole, and I have nine buttons that flash to show either true or false answers.
I have two textViews. One displays romaji and the other ...
-1
votes
3
answers
315
views
how to prevent Out Of Memory because of many Runnables [closed]
I need to run 100 tasks. I want to run them in parallel, but only 10 simultaneously. I can use for it simple
ExecutorService service = Executors.newFixedThreadPool(10);
then create 10 Runnables and ...
0
votes
2
answers
62
views
Why Synchronization not working properly with while extending to Thread?
Currently, I'm studying "synchronization", while I was doing an exercise on the synchronization method I couldn't able to get a proper output but when I'm trying the same exercise by ...
0
votes
1
answer
68
views
How can I convert an AsyncTask to a Runnable?
I want to set bitmap for ImageView. I have the URL from Firebase stroage, I use the BitmapFactory to turn to picture, I need to apply it on ImageView, I can do it with AsyncTask but I don't know how ...
0
votes
1
answer
58
views
Get width of two elements after the drawing phase at the same time
I have seen in the following answer: https://stackoverflow.com/a/24035591 of another post that to get the width of an element after the drawing phase I can do the following:
@Override
protected void ...
0
votes
0
answers
14
views
Why else part is working well but not if Part, even when I am on mainThread and I do not need to use Handler to post the task to MainLooper
Private void execute(final Runnable runnable) {
if (Looper.getMainLooper() == Looper.myLooper()) {
runnable.run();
// Here I want to update on UI but it does not update or run UI. but when I ...
0
votes
0
answers
130
views
Is there an Python function equivalent for Java's Runnable? (Multiple Lines) [duplicate]
I'm converting some Java examples to Python and I've seen direct function callers in these examples. Well, there's no problem, because I'm using lambda when it is one line (It's totally fine). However,...
0
votes
0
answers
90
views
How can I break a while loop with ServerSocket.accept() inside without throwing exception?
I connect multiple clients to a server using Sockets and a ServerSocket. Currently my servers run() method has a while(bool) loop that creates a new socket whenever a client tries to connect but I ...
1
vote
1
answer
77
views
Best approach to manage parallel threads with a set of ip addresses using ExecutorService
I have a set of 255 ip addresses to manage (x.x.x.1 -> x.x.x.255).
In Java if I check connection from my java mobile app with only one array of IP with a setTimeout(200) I could wait too much till ...
0
votes
0
answers
24
views
How to run runnable cells in vscode on a remote instance (GCP instance in my case)
I am trying to run a runnable cell in vs code, which is connected currently to a GCP instance. When I try to run a runnable cell in local, it works fine, but not on any remote instance. I get the same ...
0
votes
0
answers
38
views
Collections.sort with comparator inside runnable return duplicated items?
i am trying to sort a list of contacts(android/car/telephony/common/Contact.java) that does not contain duplicated items:
private void updateSortedContactList() {
if (mContactListLiveData....
0
votes
0
answers
146
views
Android Service : java.lang.IllegalStateException: Calling View methods on another thread than the UI thread
I have been searching and trying many things from few days but nothing worked..
I have an appwidget. It has a Service and an Activity(launched when clicked on the button of widget).
This app widget ...
0
votes
1
answer
95
views
Should I use Thread and .join or Callable along with Future and .get?
I am writing a simple thread that simply run a process and reads the InputStream.
While reading the input, if it finds a certain string it sets a boolean to true.
Then when I need to check that ...
0
votes
0
answers
74
views
How do I kill a blocking thread? (Cannot check for interruption)
I have a thread that is running a runnable with just one command, that will block forever:
mainRunnable = new Runnable(){
public void run(){
startClient();
}
};
This is not a normal ...
0
votes
0
answers
35
views
android timer loop in a thread to be accessible multiple activities
I’m working on a small project that sends and receives data via Bluetooth between an Android Tablet and an Arduino board.
My application has two separate Activities (Configure and Operate) that needs ...
0
votes
1
answer
121
views
How to refresh a recyclerview adapter to show the pool thread progress
I have a list of process into a pool of threads, I show the progress of the process in every item of the recycler view, and I need to refresh the adapter in order to show the new process processing in ...
0
votes
1
answer
203
views
How to run a map of runnables in order
I'm trying to make a method that runs a series of steps defined by lambdas. Each of those steps can be anything, they will be defined in different parts of the code, but they share some logic that has ...
0
votes
1
answer
104
views
How to set negative translationX before app load
when I set a view's translationX whether via XML or programmatically android seems to ignore the code.
When I run view.setTranslationX(-200); it ignores the translation and the app shows the view at ...
0
votes
1
answer
529
views
Tasks Queue for Android - Kotlin
I want to add Tasks (or Runnable) in queue that I want to execute in series. New task comes in at run time, depending on conditions.
I also want to add a delay after each task before it starts the ...
2
votes
2
answers
62
views
I want to stop a group of completed threads, wait for uncompleted threads
I need a group of threads to run at the same time, and then another group of threads after that. For example, 10 threads start working, and then 10 or 15 other threads.
Of course, the first approach I'...
0
votes
1
answer
409
views
Logging tasks that were being processed by ExecutorService when it was shut down
I'm working on a Spring Boot application that accepts requests and processes them using an ExecutorService. Each task submitted to the ExecutorService is non-iterative, long-running and is non-...
0
votes
1
answer
54
views
How to use existing Objects in an overwritten run() Method?
I'm a beginner in programming and do strugle a bit.
So I'm building a TCP peer to peer Chat and that requires me to divide the tasks -> Threads.
So I want to built a Thread for the "writing&...
0
votes
1
answer
486
views
Null Pointer Exception when Calling repository in a class implementing Runnable
I have a project in which there is a use case where a user books a meeting lets suppose for 10am to 11 am with another user. Now on the backend i want to check at 11 am if the meeting went well or not....
0
votes
3
answers
123
views
How Can I Save A Value From Runnables In Kotlin?
lateinit var sharedPreferences : SharedPreferences
var number = 0
var runnable : Runnable = Runnable{ }
var handler : Handler = Handler(Looper.getMainLooper())
override fun onCreate(...
1
vote
1
answer
47
views
Updating JPanel based on results from slow server (Using threads to not block GUI)
So I have been looking to update one of my panels in a my client code with data that comes from a server in Indonesia. The delay is rather long (2-8) sec and Im noticing that my UI is freezing during ...
0
votes
1
answer
269
views
Android :switch between Layouts dynamically every 10 seconds
android beginner here. any help is much appreciated .
I am working on an app that can do a simple experiment.
the app displays images and asks users to rate it from 1 to 10.
I have 1 activity and two ...
0
votes
0
answers
32
views
Stop handler if no more files are found
I am doing a project in android.I am trying to get the names of files one by one in Toast .My problem is how to stop the handler if there are no more files available
Here :
private void finder (){
...
-2
votes
2
answers
693
views
Does java ExecutorService.awaitTermination() block the main thread and wait?
I've this test code:
ExecutorService executor = Executors.newFixedThreadPool(3);
executor.execute(new Runnable() {
@Override
public void run() {
try {
System.out....
2
votes
3
answers
308
views
Jdk failed to compile my code that throws exception inside Runnable [duplicate]
I'm trying to throw exception from within a Runnable object, like this:
class ExceptionRunnable implements Runnable {
@Override
public void run() throws Exception {
throw new Exception(...
0
votes
1
answer
61
views
What's the risk if I replace AtomicBoolean with volatile in this code?
I'm reading JCP 7.2.4, it has the following code:
boolean checkMail(Set<String> hosts, long timeout, TimeUnit unit)
throws InterruptedException
{
ExecutorService exec = ...
1
vote
1
answer
143
views
JAR file won't run
I recently wrote a simple calculator using Maven and JavaFX, nothing special. The code runs without problems, all operations occur without problems - I try to compile the jar file, I compile it, but ...
0
votes
1
answer
36
views
Runnable error After Asynchtask replacement
I am getting an error on the last line below after replacing my asynctask with a runnable to upload data to server: Any pointers will be appreciated.
Cannot return a value from a method with void ...
1
vote
1
answer
556
views
Find elegant way to wrap runnable method and pass it as a function in java
Im with java 11, Let's say I have multiple runnable methods all them are same structure except the number of parameters as in example:
private Runnable deleteIndex(String targetIndex) {
return ...
1
vote
2
answers
530
views
Can Runnable be used for non-thread related things? [duplicate]
I am curious, can we use the functional interface Runnable also for non-thread related purposes?
I see it only being used by classes like Thread, ExecutorService and similar, for thread-related topics....
0
votes
1
answer
1k
views
Calling a suspend function from inside Runnable.run()
I think conceptually this should work. But there is an error:
Suspend function 'dueWorkingHours' should be called only from a coroutine or another suspend function
Is Java and Kotlin parallelization ...
0
votes
0
answers
62
views
Multi- threading in Java - trouble with implmenting in program
I created the below bouncing ball program. I'm new to programming in general, but got this working fine. The objective was to have the ball bounce within the frame and to appear in random locations at ...