I am working on an api to make batch requests through HTTP. Suggested by this (), I decided to use Multithreading.   Here is the implementation:    public class GetItems { //Control the number of connections made to the server. PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); cm.setMaxTotal(120); cm.setDefaultMaxPerRoute(30); HttpClient httpClient = HttpClients.custom()     .setConnectionManager(cm)     .build();  //Using concurrent map to store the result from different threads private Map&lt;String, ItemAttributesFromDatapath&gt; itemDataMap = Maps.newConcurrentMap();  //requests' batch private List&lt;Request&gt; requests;  public List&lt;String&gt; call() {         List&lt;Thread&gt; threads = Lists.newArrayList();         requests.forEach(request -&gt; {             Thread thread = new Thread(new GetTask(client, request));             thread.start();             threads.add(thread);         });          threads.forEach(thread -&gt; {             try {                 thread.join();             } catch (Exception ex) {                 LOGGER.error(ex);             }         });  }  //Inner class for multi-thread. public class GetTask implements Runnable{          private CatalogHttpRequest request;         private CatalogHttpClient client;         private String asin;          public GetTask(HttpClient client, final HttpRequest request) {             this.request = request;             this.client = client;         }          @Override         public void run(){             try{                HttpResponse response = client.executeHttpRequest(request);                 try {                     if (response.isOK()) {                         //some logic here                         String item = handle(response)                         itemDataMap.put(itemId, item);                      } else {                         String message = "Is Client Error";                         LOGGER.error(message);                      }                 } catch (Exception ex){                     LOGGER.error(ex.getMessage());                  }             } catch (Exception ex) {                 LOGGER.error(ex.getMessage());             }         }     } }   Then I tried to write unit-test,   @Test public void testBatchRequest() throws Exception{ HttpClient = mockClient(...); GetItems batch = new GetItems(...); List&lt;String&gt; ret = batch.call();}   Inside mockClient method, I mock some class using Mockito:   private HttpClient mockSuccessfulClient(InputStream responseStream, int code) throws IOException{          HttpEntity entity = Mockito.mock(HttpEntity.class);         when(entity.getContent()).thenReturn(responseStream);          HttpResponse response = Mockito.mock(CloseableHttpResponse.class);         when(response.getEntity()).thenReturn(entity);          StatusLine statusLine = Mockito.mock(StatusLine.class);         when(statusLine.getStatusCode()).thenReturn(code);         when(response.getStatusLine()).thenReturn(statusLine);          //CloseableHttpClient httpClient = Mockito.mock(CloseableHttpClient.class);         //when(httpClient.execute(any())).thenReturn(response);           CatalogHttpClient client = Mockito.mock(HttpClient.class);         when(client.executeHttpRequest(any())).thenReturn(response);          return client;     }   For the unit-test right now, the return list is empty, which is incorrect.   I tried to debug the code by setting up breaking point and found the main code didn't execute run() method inside GetTask when thread starts.   Since I am not familiar with multi-thread stuff. This problem may seem dumb to you, but can you help me figure out what's wrong in my code and how to write the proper test for my case.  Also, I am not sure if the ConcurrentMap is a good practice to store the results across multiple threads?
I have thus far avoided the nightmare that is testing multi-threaded code since it just seems like too much of a minefield.  I'd like to ask how people have gone about testing code that relies on threads for successful execution, or just how people have gone about testing those kinds of issues that only show up when two threads interact in a given manner?  This seems like a really key problem for programmers today, it would be useful to pool our knowledge on this one imho.
All rounds of AES (and Rijndael) have a MixColumns step, save the last round which omits it.  DES has a similar feature where the last round differs slightly.  The rationale, if I recall correctly, was to "make the cipher appear similar in reverse as it does in the forward direction."  Why does this make AES$^{-1}$ look similar to AES?  And how does this help in implementing the block cipher? FrameLabel and OverTilde Upper bound on the number of charts needed to cover a topological manifold If $M^n$ is a compact topological manifold (not necessarily with additional structure), is there an upper bound on the number of charts needed to cover $M$ ? Does this bound depend on the dimension of $M$ ?  Thanks in advance...  Cheers How to install applications to a separate hdd? I was so good with windows, now I’m feeling like a complete idiot.  I have an SSD for ubuntu and want to install the majority of my programs to a separate HDD but I have no clue how. All searches I have tried only turn up with dual-boot installations.   (RESOLVED -> ) I am also having trouble locating "/etc/". Specifically, to modify Conky. Searching for this term only turns up instances where people are telling you to access this file, not how to get to it. Generating random numbers without repetitions How to code to skip a shapefile, if it doesn't exist? So if shapefile 'AAA010' does not exist, how can I skip the Merge and Clip and move on to the next part of the script? If possible I would like to keep the current script as it is, but by just adding else or if, Sorry still trying to learn the ins and outs.  import os, fnmatch, arcpy   arcpy.env.workspace = r'C:\Users\sysadmin\Desktop\DataMagement\Comp_3\SA_MGCP3.gdb'   fcMerged = 'MergedFeatureClass' fcClipped = 'fcClipped' fcToClip = r'C:\Users\sysadmin\Desktop\DataMagement\Country.shp'  filesMatched = list()  for root, subfolders, files in os.walk (r'C:\Users\sysadmin\Desktop\DataMagement\MGCP_Raw'):      for f in fnmatch.filer(files, 'AAA010.shp'):              filesMatched.append(os.path.join(root,f))      if filesMatched:         print ' files found - merging'         arcpy.Merge_management (filesMatched, fcMerged)         arcpy.Clip_analysis (fcMerged, fcToClip,fcClipped)      else:          print 'nothing found - skipping' How to calculate the summation $(\sum_{p = k}^{n} \binom{n}{p}) / 2^n$ quickly? I was solving a question which technically reduces to the following     Given $N$ items, it is equiprobable for each item to be good or bad, what is the probability that number of good items in the set are greater than or equal to $K$.   This can be reduced to $\dfrac{x}{2^n}$ where $\displaystyle x = \sum_{p = k}^{n} \binom{n}{p}$. Is there a more simplified form which is easier to calculate for large values of $N, K$?  Note: It may be safe to assume that we do not require extremely high precision while calculating(first 5-10 digits only).  Thanks! Assignment statement used in conditional operators Is it possible to install Ubuntu FROM a smartphone? So, I'm in a situation were I want to install ubuntu in my laptop (currently running windows 8) but I don't happen to have pendrives, CDs or the like available. The only "external" device I have with me is a samsung galaxy s2 with a micro SD-card in it.   Is it possible to use the phone as a pendrive to install ubuntu from it somehow? (without damaging the phone's OS and data) Why should the interface for a Java class be preferred? would report a violation for:  ArrayList&lt;Object&gt; list = new ArrayList&lt;Object&gt;();   The violation was "Avoid using implementation types like 'ArrayList'; use the interface instead".  The following line would correct the violation:  List&lt;Object&gt; list = new ArrayList&lt;Object&gt;();   Why should the latter with List be used instead of ArrayList? What is the difference between a builtin command and one that is not? I get a "serious errors while checking the disk drives for /boot" error while booting I have just set up my new system by creating three partitions on a whole hard disk (/boot, /home, swap and /). I saw  article and now I am getting those errors and the system provide me with some options: (I to ignore, S to skip mounting or M for manual recovery).   I am forced to choose skip mounting because I don't know what manual recovery is. Despite the error I get I think that the system boots okay because I can use the system but this error is very annoying. If the dot product between two vectors is $0$, are the two linearly independent? If we have vectors $V$ and $W$ in $\mathbb{R^n}$ and their dot product is $0$, are the two vectors linearly independent?  I can expand $V_1 \cdot V_2 = 0 \Rightarrow v_1w_1+...+v_nw_n = 0$, but I don't understand how this relates to linear independence. Evaluation of $\int\frac{1}{x^2.(x^4+1)^{\frac{3}{4}}}dx$ What are the effects of exceptions on performance in Java? Question:  Is exception handling in Java actually slow?  Conventional wisdom, as well as a lot of Google results, says that exceptional logic shouldn't be used for normal program flow in Java.  Two reasons are usually given,   it is really slow - even an order of magnitude slower than regular code (the reasons given vary),     and    it is messy because people expect only errors to be handled in exceptional code.     This question is about #1.  As an example,  describes Java exception handling as "very slow" and relates the slowness to the creation of the exception message string - "this string is then used in creating the exception object that is thrown. This is not fast."  The article  says that "the reason for this is due to the object creation aspect of exception handling, which thereby makes throwing exceptions inherently slow".  Another reason out there is that the stack trace generation is what slows it down.  My testing (using Java 1.6.0_07, Java HotSpot 10.0, on 32 bit Linux), indicates that exception handling is no slower than regular code.  I tried running a method in a loop that executes some code.  At the end of the method, I use a boolean to indicate whether to return or throw.  This way the actual processing is the same. I tried running the methods in different orders and averaging my test times, thinking it may have been the JVM warming up.  In all my tests, the throw was at least as fast as the return, if not faster (up to 3.1% faster).  I am completely open to the possibility that my tests were wrong, but I haven't seen anything out there in the way of the code sample, test comparisons, or results in the last year or two that show exception handling in Java to actually be slow.  What leads me down this path was an API I needed to use that threw exceptions as part of normal control logic.  I wanted to correct them in their usage, but now I may not be able to.  Will I instead have to praise them on their forward thinking?  In the paper , the authors suggest that the presence of exception handlers alone, even if no exceptions are thrown, is enough to prevent the JIT compiler from optimizing the code properly, thus slowing it down.  I haven't tested this theory yet. What does unwrapping a model do and why is it important? When using zero as a quantifier, is it correct to use the singular form on the object of the quantifier, or the plural form?  It sounds confusing when I put it that way, but what I mean is: Which is correct?   Your password expires in 0 days. Your password expires in 0 day.   Essentially I suppose I'm asking, does "singular" mean "one" or "the opposite of more than one", as zero is not "plural" in the traditional "more than one" sense?  I'm pretty sure "days" sounds correct, but I can't be sure. Complexity of $T(n) = 2T(n/2) + n$ How old is too old for a PhD? Are there any age limits (formal, informal, or guidelines) that schools use when deciding to accept someone into a PhD program? I'm most curious about the upper age limits. For example, will most schools accept someone in their 40's? How about their 50's? Why and how does C# allow accessing private variables outside the class itself when it's within the same containing class?