runnable

Java: return results from Runnable

南楼画角 提交于 2019-12-08 20:05:31
Suppose the following simplified example. Let B represent a class processing some raster data: import java.awt.image.BufferedImage; public class B implements Runnable{ private boolean c; private Runnable f; public B (boolean c_, Runnable f_) { c = c_; f = f_;} public BufferedImage process() { //Some operations BufferedImage output = null; if (c) output = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB); return output; } public void run() { process();} } The process() method may but may not create an output rater. Due to the computational cost, the procedure runs in a separate thread.

Generate a runnable jar and include libraries in it with Maven

只愿长相守 提交于 2019-12-08 18:32:32
I'm trying to compile a Java project with Maven and Eclipse but I tried a lot of solutions seen on the web but none of them seem to work. I just want to build the application, create a runnable jar and include the needed libraries. I tried maven-dependency or maven-assembly but I surely miss something because I fail every time. Here is my pom.xml, is it ok or does it miss something? <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

How to remove/postDelayed runnables in Java?

。_饼干妹妹 提交于 2019-12-08 07:23:06
问题 Upon an event, I'd like to run a task/runnable but delay it's execution in 2 seconds. During these 2 seconds, if the same event occurs, I'd like to remove the previous task and re-post it to run - again delayed by 2 seconds. An example scenario would be background compilation. When a file is saved, I'm waiting 2 seconds and start compiling the class and other, depending classes. I don't want to do it all the time - especially if there are editors that save files automatically, like IntelliJ

Runnable JAR file error: Unsupported major.minor version 51.0

大憨熊 提交于 2019-12-08 06:52:59
问题 I made an application in Java (version 7) with Eclipse (Indigo) when I exported my application interface on a Runnable JAR file on my computer and tried it worked fine, then I tried on another computer and I get this problem Exception in thread "main" java.lang.UnsupportedClassVersionError: cliente/Princ ipal : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(Unknown Source) at java.lang.ClassLoader.defineClass

Android How to call a method multiple times with a delay between them

这一生的挚爱 提交于 2019-12-08 04:14:03
问题 I would like to ask, if is there a better away to call a method multiple times giving a 5 sec delay between each call. But I really want is to call the Toas() method about 7 times, and with my code below, it doesnt look right. Thanks guys @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ... CallMultipleToast(); ........ private void CallMultipleToast(){ Runnable call_1 = new Runnable() { @Override public void run() { Toast("Message one");

Generate a runnable jar and include libraries in it with Maven

别来无恙 提交于 2019-12-08 03:45:27
问题 I'm trying to compile a Java project with Maven and Eclipse but I tried a lot of solutions seen on the web but none of them seem to work. I just want to build the application, create a runnable jar and include the needed libraries. I tried maven-dependency or maven-assembly but I surely miss something because I fail every time. Here is my pom.xml, is it ok or does it miss something? <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi

ScheduledExecutorService - Task stops running

∥☆過路亽.° 提交于 2019-12-08 03:14:56
问题 private ScheduledExecutorService pool = new ScheduledThreadPoolExecutor(20); I'm running a task public void run() { if (queue.isEmpty()) return; ArrayDeque<Profile> current = new ArrayDeque<Profile>(); this.queue.drainTo(current, 20); MySQLStatement statement = this.wrapper.prepare(); while (!current.isEmpty()) { if (statement.isClosed()) return; Profile profile = current.poll(); statement.addBatch(profile.getId().toString(), ProfileBuilder.toJson(profile)); } statement.executeBatchAsync(); }

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

蓝咒 提交于 2019-12-07 18:48:48
问题 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

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

萝らか妹 提交于 2019-12-07 18:24:50
问题 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

ScheduledExecutorService execute every night at 12 AM UTC Time

倾然丶 夕夏残阳落幕 提交于 2019-12-07 08:58:39
问题 I want to start ScheduledExecutorService exactly 12 AM daily ,Schedule has to Start at today at 22/02/2017 00:00:00 (UTC TIME),Can any one tell me Whether my code is Correct or not? DateTime today = new DateTime().withTimeAtStartOfDay(); DateTime startOfTommorrow = today.plusDays(1).withTimeAtStartOfDay(); Long midnight = startOfTommorrow.getMillis(); long midnights = (midnight / 1000) / 60; final DateFormat nextDateTymFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); System.out.println("