runnable

Loop with delay period

隐身守侯 提交于 2019-12-07 07:53:04
问题 I have a TextView and I want each second to highlight another letter in the word. For example: h e l l o - h e l l o - h e l l o - h e l l o - h e l l o What I have done: int i = 0; String text; Handler handler = new Handler(); public void spanText(String txt) { text = txt; for(int i=0; i<text.length(); i++) { handler.post(runnable); } Runnable runnable = new Runnable() { @Override public void run() { Spannable spannable = Spannable.Factory.getInstance().newSpannable(text); StyleSpan style =

Creating Jar file - doesn't work on other computers

﹥>﹥吖頭↗ 提交于 2019-12-07 04:59:07
问题 I'm trying to package my program into a JAR file so it can be used on multiple computers. My program is composed of start.java , userinterface.java and writer.java . The program, written in Eclipse, works perfectly on my computer. When exported, it will work on my computer but cause the following error on other computers: "Could not find the main class: start. Program will exit". Again, my program runs fine on my computer when I double click on it. I've tried creating the JAR file via command

Java: How do I catch InterruptedException on a thread, when interrupted by another thread?

半腔热情 提交于 2019-12-07 02:15:27
问题 I'm developing a multithreaded application to make connections to external servers - each on separate threads - and will be blocked until there is input. Each of these extends the Thread class. For the sake of explanation, let's call these "connection threads". All these connection threads are stored in a concurrent hashmap. Then, I allow RESTful web services method call to cancel any of the threads. (I'm using Grizzly/Jersey, so each call is a thread on its own.) I retrieve the specific

how to package images into a Runnable JAR

若如初见. 提交于 2019-12-06 12:36:07
Before ... (question deleted) I'm trying to make a runnable jar from a Swing project. I add some images in /img folder. Previous version didn't have it and runnable jar was good through export in Eclipse. Now I guess something is going wrong. In runnable jar I added at same level of main package and META-INF folder, this img folder but it seems GUI does not appear. Some process before building GUI went good so main class seems ok. Any suggestion!? Thanks. Comments : Run it on the command line and post the error you get. – Kevin Any suggestion!?. Yes. post the structure of the jar file, the

Combining two Runnable objects

◇◆丶佛笑我妖孽 提交于 2019-12-06 10:43:49
Say for example that I have a Runnable called RunnableA that does something. I also have a Runnable called RunnableB that does something else. Is there a way that I can combine these two Runnables someway so that they will run in the same thread? The second part of the question is if this is possible, can I then specify the order that they will run in? EDIT!: The reason why I wanted to do this was because I need to run code on the EDT but some of the other code needs to be run on another thread. Please take a look at the code below. Something like this public final class CompoundRunnable

pass a runnable to a pre-existing thread to be run in Android/Java

百般思念 提交于 2019-12-06 09:21:27
I have a question related to the following link: What's the difference between Thread start() and Runnable run() In this question, I see a person creating runnable objects and then initializing them in two different ways. So, does this mean that you could pass these runnables around to other things at run time? I want to pass code to a preexisting thread to be executed within that thread's loop. I was looking around and from what I can tell, you would want to create a dedicated runnable class like the following: public class codetobesent implements Runnable { public void run() { ..morecodehere

Will Runnables block the UI thread?

倾然丶 夕夏残阳落幕 提交于 2019-12-06 08:15:54
I am trying to understand how UI thread's event queue works. I'm trying to run a code that can be broken into many parts but unfortunately it must run on the UI thread. So, in order to not block the UI thread and receive a ANR I was wondering if I can break that code in many Runnable objects and run them using runOnUiThread from another thread. My question is, will this block the UI thread? If, for example, I have a piece of code that definitely runs in over 5 seconds and I break this code into, let's say 1000 Runnable objects, and add them to the event queue of the UI thread, will other

Why should I use a separate thread to show a GUI in JAVA

谁说胖子不能爱 提交于 2019-12-06 07:18:28
问题 This simple issue confuses me. You can display a JAVA GUI application by setting the frames' setVisible property true . But in almost all the examples I found on internet they use a separate thread to do the same thing. They do something like this, SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new Frame().setvisible(true); //just take the idea of this line } }); I found no difference between the two methods. But there must be some special reason, that's why

Is adapting a no-arg method into a Consumer bad form?

好久不见. 提交于 2019-12-06 06:30:35
Someone raised a question on another SO Answer about whether it is bad practice or inefficient to do this: Optional<User> user = ... user.ifPresent(u -> doSomethingWithoutUser()); instead of if (user.isPresent()) doSomethingWithoutUser(); Specifically, the fact that we're adapting a zero-arg method into a Consumer<User> which ignores its parameter u . As this isn't a Stream non-terminal operation, the fact doSomethingWithoutUser() likely has side-effects isn't a concern. I'm not bothered about the specifics of this one-line Optional example, it could the result of a long chain of functional

Android thread runnable performance

强颜欢笑 提交于 2019-12-06 05:49:59
问题 I'm wondering about performance and cpu/ram requirements for 2 different methods of starting runnables I have some code that collects sensor data every 10ms and inserts the values into a database on a background thread (using a single thread executor). Executor service is created as follows: executor = Executors.newSingleThreadExecutor(); One way to do that would be something like... public void onSensorChanged(SensorEvent event) { //get sensor values //insert into database executor.execute