I have one method m1() which calls another method m2(). As m2() is a long running method, I want to wait for it to return say for 10 secs and if not then I use a default value. Is there a way in Java where I can say run this method for at most this much time or return so that I don't have to wait long. Well I can do Thread.currentThread().sleep(x) but then even if my method returns earlier I will have to wait till x time.   So based on the answers, I wrote below Class:  I am using sleep in Callable so that it exceeds the call to get method, But it still return 1. What is wrong?     public class RunMethodAtMostForGivenTime     {         public static void main(String[] args)         {         RunMethodAtMostForGivenTime obj = new RunMethodAtMostForGivenTime();         System.out.println(obj.sum());         }          private int sum()         {         int sum = 1;         ExecutorService service = Executors.newFixedThreadPool(1);         int returnedInt = 0;         Future&lt;Integer&gt; calculatedIntFuture = service             .submit(new Callable&lt;Integer&gt;() {                 @Override                 public Integer call() throws Exception                 {                 Thread.currentThread().sleep(110);                 return new Integer(1);                 }             });         try         { //here wait is for 10 milliseconds and callable thread sleeps for 110 milliseconds so expected returned value is 0 not 1.             returnedInt = calculatedIntFuture.get(10, TimeUnit.MILLISECONDS);             sum += returnedInt;         }         catch (InterruptedException e)         {             e.printStackTrace();         }         catch (ExecutionException e)         {             e.printStackTrace();         }         catch (TimeoutException e)         {             e.printStackTrace();         }         return sum;         }     }
I have a method that I would like to call.  However, I'm looking for a clean, simple way to kill it or force it to return if it is taking too long to execute.  I'm using Java.  to illustrate:  logger.info("sequentially executing all batches..."); for (TestExecutor executor : builder.getExecutors()) { logger.info("executing batch..."); executor.execute(); }   I figure the TestExecutor class should implement Callable and continue in that direction.  But all i want to be able to do is stop executor.execute() if it's taking too long.  Suggestions...?  EDIT  Many of the suggestions received assume that the method being executed that takes a long time contains some kind of loop and that a variable could periodically be checked. However, this is not the case.  So something that won't necessarily be clean and that will just stop the execution whereever it is is acceptable.
Was PreferenceFragment intentionally excluded from the compatibility package? Show that any monotone boolean function can be realize by the following connectives. I am always confused about where to put adverbs in sentences. For example, consider the questions below:        Why did they target us specifically?   Why did they target specifically us?   Why did they specifically target us?      I believe all these sentences mean the same. Am I correct? I am always confused about where to put adverbs such as always and specifically, etc. Is there a particular grammar rule for this?  Funny, you see, I can even form the above sentence in different ways.         I always confuse where to put this kind of adverb   Always I confuse where to put this kind of adverb pyvenv vs venv vs python-virtualenv vs virtualenv and python 3 malikarumi@Tetouan2:~$ pip install virtualenv     Collecting virtualenv     Downloading virtualenv-12.0.7-py2.py3-none-any.whl (1.8MB)     100% |################################| 1.8MB 330kB/s   malikarumi@Tetouan2:~$ pip freeze     (a lot of stuff, but not virtualenv)  malikarumi@Tetouan2:~$ virtualenv testvenv1     The program 'virtualenv' is currently not installed. You can install it by typing:     sudo apt-get install python-virtualenv   What is going on here? is python-virtualenv == pyvenv? Isn't that still broken? Does original virtualenv still work with python? if venv (too many name variations!!!) is part of the standard library, , why am I being told to install it?  And when I did try to install it, I got:  malikarumi@Tetouan2:~$ sudo apt-get install python-virtualenv     Reading package lists... Done     Building dependency tree            Reading state information... Done     The following extra packages will be installed:     python-colorama python-distlib python-html5lib python-pip python-setuptools   At which point I aborted, because installing python3-pip just before that had given me   Setting up python3-setuptools (3.3-1ubuntu1) ... Setting up python3-pip (1.5.4-1) ...   And I wasn't sure if the extra packages would overwrite them or go onto python 2.7.  I read that python 3 is supposed to be the default going forward. Since both 2.7 and 3.4 are there, and have separate commands, how do I not only make sure Python 3 is my default, but that anything I install goes there and is used by it instead of 2.7?   BTW, I tried sudo apt-get python3-virtualenv and got: E: Unable to locate package python3-virtualenv How does extra damage work for critical hits? I'm a bit confused on how extra damage works for critical hits. Let's take the following example: A thief with sneak attack rolls a crit. I'm under the impression he rolls double his normal attack damage dice AND double his Sneak Attack damage dice. Is this accurate? Another example, I finished DM-ing my first campaign recently. The Giant Spider enemy monster has an melee attack that causes a constitution saving throw. If the player fails, the enemy rolls an additional 2D8 of damage. In this situation, if there was a critical hit, and the player failed their saving throw, would I also roll double dice on the additional damage? Or is that considered a separate attack? There is no or there was no I read a sentence in an exam:     There is no child who did not bring his parents to the picnic.    I think that the sentence does not have tense-agreement. Why is is used instead of was? Please explain it to me. I came across a map and when I was playing I found some coloured and bolded item names. I thought it isn't possible as at most you can only use the custom name tag to rename things! Is there a way to colour and bold item names in vanilla Minecraft? External programs are OK. Oh, and the wiki page of formatting codes doesn't really do much. I am running Ubuntu 18.04. I wanted to install node and npm on my machine. The apt repository version of node is 8.x, whereas I wanted to have version 12.x (Current LTS version).  I followed the guide here:   As per the guide, I downloaded curl -sL https://deb.nodesource.com/setup_12.x -o nodesource_setup.sh  and then ran it with sudo -E ./nodesource_setup.sh    However, my machine fails to run sudo apt update with the following (full) output:  maxim@fujitsu:~/scripts$ sudo apt update Hit:1 http://gb.archive.ubuntu.com/ubuntu bionic InRelease                  Hit:2 http://gb.archive.ubuntu.com/ubuntu bionic-updates InRelease          Get:3 http://security.ubuntu.com/ubuntu bionic-security InRelease [88.7 kB] Hit:4 http://gb.archive.ubuntu.com/ubuntu bionic-backports InRelease               E: Repository 'http://security.ubuntu.com/ubuntu bionic-security InRelease' changed its 'Suite' value from 'bionic-updates' to 'bionic-security' N: This must be accepted explicitly before updates for this repository can be applied. See apt-secure(8) manpage for details. Do you want to accept these changes and continue updating from this repository? [y/N] N Fetched 88.7 kB in 8s (10.5 kB/s)                                                       Reading package lists... Done E: Failed to fetch http://security.ubuntu.com/ubuntu/dists/bionic-security/InRelease   E: Some index files failed to download. They have been ignored, or old ones used instead.    suggests that one should use apt update instead of apt-get update. None the less, I am running apt update.   suggests to answer "Y" to the prompt.  , from the Docker community, makes it clear that doing so is a bad idea.  However, , suggests that sometimes repositories change the names of package sources.  So my question is, is it OK to answer Y here? I don't want to  just blindly accept whatever error the package manager throws at me. Can sum of a rational number and its reciprocal be an integer?   My brother asked me this question and I was unable to answer it.   The only trivial solutions which I could think of are $1$ and $-1$.  As to what I tried, I am afraid not much. I have never tried to solve such a question, and if someone could point me in the right direction, maybe I could complete it on my own.  Please don't misunderstand my question.   I am looking for a rational number $r$ where $r + \frac{1}{r}$ is an integer. Who provides the Internet service to Internet Service Providers (ISPs)? I've been wondering recently about how the infrastructure of the Internet really works.    I know that I have an Internet Service Provider (ISP) that supplies my connection to the Internet.   But what I don't know is: Who provides the Internet to the ISP?  And who supplies it to them? Is there a never-ending loop that eventually connects us all together? Why did Slytherin House not get disbanded? Moderators currently have a tool to add a Post Notice that says:     insufficient explanation       We're looking for long answers that provide some explanation and   context. Don't just give a one-line answer; explain why your answer is   right, ideally with citations. Answers that don't include explanations   may be removed.   However, there seems to be no equivalent wording for one-line questions.  Could the wording be changed to something like below to cover both one line questions and one-line answers?     insufficient explanation       We're looking for longer posts that provide some explanation and context.          Don't just ask a one-line question; provide some background like a brief description of your research prior to asking   Don't just give a one-line answer; explain why your answer is   right, ideally with citations.          Questions and answers that don't include explanations may be removed.   Sometimes such questions can simply be closed for being unclear or too broad but on the two sites I moderate there is an aversion to closing questions from new users, so to give them some guidance about what is expected, without spending time writing the same comment over and over, a post notice like this would provide a good "couple of clicks" alternative. Protect .NET code from reverse engineering? What is the reason Men play 5 sets & Women play 3 sets in a Grand Slam in Tennis? In the ATP &amp; WTA events, both Men &amp; Women tennis players play best of 3 sets. But when it comes to Grand Slams, the Men play 5 sets. At the risk of sounding a misogynist, I always believe the reason to be strength &amp; endurance. After all, a 5 set EPIC match lasts 5 hours while a 3 set EPIC last 3 hours.    Is that the only reason. Or am I a naive misogynist? Also was that the case since the history of Grand Slams or did Men play 3 sets before? In  video, he uses a command block to give him jump boost while he is wearing his Boots of Leaping.  I am trying to imitate this for a multiplayer map I am making. Wearing golden boots called "Stealth Boots" is supposed to give that player invisibility. I am using this command:  /effect @a[Inventory:[{Slot:100b,tag:{display:{Name:"Stealth Boots"}}}]] 14 30000 200  I do know that in the video he is using a /testfor command, but since I'm making a multiplayer map in order to use this technique I'd have to define a scoreboard variable for each player - and even then, the players would be finite. Thus, I want to be able to use the command DIRECTLY.  When I use that command, it either says "That player cannot be found" or "The entity UUID provided is in an invalid format" - the former of which I'm familiar with; the later I've barely ever seen before.  So, my method doesn't seem to work - how do I fix it? Recently, I found this , that allows you to generate a 3D model from a 2D image.   It works very well and you can download an OBJ file. Vertex are colored and when I import it using Blender, I can't see any Vertex color.   Using Cycle (I prefer a internal solution if it exists) according to some answers I've found on Blender Stack Exchange, I patched some nodes : Attribute -> Diffuse BDSF -> Material Output.  Unfortunately, I can't get it works, the model stills black.    When I open the OBJ file, I see that color per vertex are there :  v 43.747554 107.000000 69.000000 0.470588 0.380392 0.309804 v 43.780163 115.000000 64.500000 0.427451 0.337255 0.266667 v 43.782527 107.000000 68.500000 0.470588 0.380392 0.309804 v 43.801902 115.000000 65.000000 0.427451 0.337255 0.266667 v 43.806461 107.000000 69.500000 0.470588 0.380392 0.309804 v 43.821703 115.000000 64.000000 0.427451 0.337255 0.266667 v 43.838352 108.000000 68.500000 0.466667 0.376471 0.305882 v 43.854670 106.000000 69.000000 0.482353 0.392157 0.321569 v 43.856176 108.000000 69.000000 0.466667 0.376471 0.305882 v 43.873876 106.000000 69.500000 0.482353 0.392157 0.321569 v 43.888855 110.000000 68.000000 0.466667 0.376471 0.305882 v 43.891471 109.000000 68.000000 0.466667 0.376471 0.305882 v 43.892733 110.000000 67.500000 0.466667 0.376471 0.305882 v 43.895170 108.000000 68.000000 0.466667 0.376471 0.305882 v 43.900904 109.000000 68.500000 0.466667 0.376471 0.305882 v 43.907584 107.000000 68.000000 0.470588 0.380392 0.309804 v 43.917898 115.000000 65.500000 0.427451 0.337255 0.266667 v 43.925000 111.000000 67.500000 0.454902 0.364706 0.294118   According to some answers here, Blender import more easily the vertex color of a PLY file so I tried to convert to PLY with two different sites :   1. meshconvert .com : Give me a 3.5 Mo file  2. greentoken.de/onlineconv : Give me a 2.3 Mo file  (Of course, if you know some other sites I could try, it interest me)  I guess that color data are lost with greentoken (not sure).   When I import the 3.5 Mo PLY file in blender, I need to be in textured display mode, then I think I see my vertex color value but in black &amp; white instead of RGB, that is weird. Anyway, I can't get it work  EDIT 1 : I opened PLY files and color vertex aren't there... I need to find a better converter   EDIT 2 : I tried www.ofoct.com/3d-model-file-for-3d-printer-converter it doens't take vertex color into account. In fact, in each PLY files I converted with the various sites here, there is a common line :      comment Created by Open Asset Import Library -    (v3.2.0)   (the version varies)  EDIT 3 : In fact it seems that model converted by Green token, keep the vertex color. That is weird because that's the smallest file :   ply format ascii 1.0 comment Created by Open Asset Import Library - http://assimp.sf.net (v3.1.187496374) element vertex 29793 property float x property float y property float z property float nx property float ny property float nz element face 59582 property list uint uint vertex_index end_header 82 103 6.37528 0.40963 0.0331735 0.911648 82 102 6.57043 0.272087 0.235193 0.933088 82.6603 103 6.5 -0.14071 0.043367 0.9891 82 103.935 6.5 0.201161 -0.136681 0.969976 81.5475 103 7 0.825371 0.0489484 0.562465 83 102 6.62244 -0.248588 0.147929 0.957247 83 103 6.56417 -0.411487 -0.0867124 0.907281 81.5819 104 7 0.787841 -0.0338904 0.614946 82 105 6.63886 0.0715144 -0.131383 0.988749 83 104 6.77321 -0.431167 -0.171652 0.885794 83.6781 102 7 -0.470137 0.061235 0.880467 83.6327 103 7 -0.543939 -0.0905203 0.834228 83 105 6.96709 -0.445324 -0.163091 0.880391 84 103 7.23724 -0.520118 -0.141377 0.842313 84 104 7.47775 -0.546517 -0.195833 0.814229 84 102 7.16782 -0.416323 -0.021798 0.908955 83.3508 101 7 -0.314426 0.156435 0.936304 84 101 7.22581 -0.280388 0.0301462 0.959413 84.9009 101 7.5 -0.339848 -0.0219793 0.940223 84.6939 102 7.5 -0.435242 -0.0925323 0.895546   As you can see, nx, ny and nz correspond to RGB values.. Is "guy" gender-neutral? Does leaning (banking) help cause turning on a bicycle? Did Michael Corleone ever get revenge against those who killed his wife? Did Michael Corleone ever get revenge against those who killed his wife?   I just watched the 3 Godfather movies again and I was not able to figure out who made the attempt on his life and in the process killing his wife with the car bomb Sicily in the first movie. I know it was one of his body guards that planted the bomb, but I could not get who was actually behind it. I am guessing it was probably the Barzini crime family for the killing of Virgil Sollozzo, but I am just making an assumption there and if in fact it was the Barzini crime family then obviously he did get his revenge. I was hoping someone could back this assumption up, or not.  So did Michael Corleone ever get revenge against those who killed his wife? Callback animation to begin only after ALL children have finished animating