I have a implemented a class that acts as a Cache for objects. It has a DelayQueue for removing objects from cache.   class mySingletonClass {   ConcurrentHashMap map&lt;String,MyObject&gt;();   DelayQueue queue &lt;MyObject&gt;();     boolean alreadySeen(MyObject myObject) {     MyObject obj = map.putIfAbsent(myObject.getID(),myObject);     if(obj != null) return true;     queue.add(myObject);     return false; }   It works fine for single threaded. I am trying to test it with multiple threads concurrently. I have tried to reason about if this method is thread safe but I am unsure. I have tried the static analyzer FindBugs plugin. I am unsure how to unit test this. I have never used java.util.concurrent nor worked with threads so I am trying to learn it all relatively quickly.   My thoughts for unit testing were create an AtomicInteger and run multiple threads trying to add the same object to the map. If the method returns true increment the integer. This integer should equal one if successful. As my second test I was thinking similarly with AtomicInteger try to have maybe 10? threads with each thread adding a list of 5 unique objects and ensure the total after all threads are done is 5.  I have been playing with Executors and creating Runnable methods but I am getting NullPointerExceptions and I am not sure exactly what I am doing.  I'm looking for:   Is this method thread safe? If not is there a way to make it thread safe (other than just making the method synchronized)? How to I implement the two unit tests with multiple threads in junit4?
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.
Is this a valid partial fraction decomposition? Write $\dfrac{4x+1}{x^2 - x - 2}$ using partial fractions. $$ \frac{4x+1}{x^2 - x - 2} = \frac{4x+1}{(x+1)(x+2)} = \frac{A}{x+1} + \frac{B}{x-2} = \frac{A(x-2)+B(x+1)}{(x+1)(x-2)}$$ $$4x+1 = A(x-2)+B(x+1)$$ $$x=2 \Rightarrow 4 \cdot2 + 1 = A(0) + B(3) \Rightarrow B = 3$$ $$x = -1 \Rightarrow 4(-1) +1 = A(-3)+ B(0) \Rightarrow A = 1$$ Thus, $$\frac{4x+1}{x^2-x-2} = \frac{1}{x+1} + \frac{3}{x-2}\textrm{.}$$  The substitution of $x$ ($x = 2, -1$) is a common method to find out the coefficient of the partial fractions. However, the equation on the third line is obtained by multiplying $(x+1)(x-2)$, which is assumed to be nonzero. Here we have a contradiction. Furthermore, the original function is not defined at $x=-1,2$. How can we substitute these value for $x$? So is this method valid and rigorous? How to modify it so that it is rigorous? Accelerating particles to speeds infinitesimally close to the speed of light? I'm in a freshmen level physics class now, so I don't know much, but something I heard today intrigued me. My TA was talking about how at the research facility he worked at, they were able to accelerate some certain particle to "99.99% the speed of light". I said why not 100%, and I didn't quite understand his explanation, but he said it wasn't possible. This confused me. Since the speed of light is a finite number, why can we go so close to its speed but not quite?  Edit: I read all the answers, and I think I'm sort of understanding it. Another silly question though: If we are getting this particle to 99.99% the speed of light by giving it some sort of finite acceleration, and increasing it more and more, why cant we increase it just a little more? Sorry I know this is a silly question. I totally accept the fact we cant reach 100%, but I'm just trying to break it down. If we've gotten so close by giving it larger and larger acceleration every time, why cant we just supply it with more acceleration? And how much of a difference is there between 99.99% the speed of light, and the speed of light? (I'm not really sure if "difference" is a good word to use, but hopefully you get what I'm asking). The grammaticality of "that don't impress me much" I'd like to know how the sentence "That don't impress me much" sounds to a native English speaker.  The phrase is the title of a song by Shania Twain, and to my eyes it contains a clear error. It is obviously intended, and I want to know what was the effect that the author wanted to obtain.  Other examples that come to mind:   “She's got a ticket to ride, but she don't care” — The Beatles “My love don't cost a thing” — Jennifer Lopez “It don't matter” — Akon “She don't care about me” — heard in the Lost series “It Don't Mean a Thing” — a jazz album title “The Sun Don't Lie” — another album title If $\sum a_n b_n <\infty$ for all $(b_n)\in \ell^2$ then $(a_n) \in \ell^2$ I'm trying to prove the following:     If $(a_n)$ is a sequence of positive numbers such that $\sum_{n=1}^\infty a_n b_n&lt;\infty$ for all sequences of positive numbers $(b_n)$ such that $\sum_{n=1}^\infty b_n^2&lt;\infty$, then $\sum_{n=1}^\infty a_n^2 &lt;\infty$.   The context here is functional analysis homework, in the subject of Hilbert spaces.  Here's what I've thought:  Let $f=(a_n)&gt;0$. Then the problem reads: if $\int f\overline{g}&lt;\infty$ for all $g&gt;0,g\in \ell^2$, then $f\in \ell^2$. This brings the problem into the realm of $\ell^p$ spaces.  I know the inner product is defined only in $\ell^2$, but it's sort of like saying: if $\langle f,g\rangle &lt;\infty$ for all $g&gt;0,g\in \ell^2$ then $f\in \ell^2$.  I read this as: "to check a positive sequence is in $\ell^2$, just check its inner product with any positive sequence in $\ell^2$ is finite, then you're done", which I find nice, but I can't prove it :P  From there, I don't know what else to do. I thought of Hölder's inequality which in this context states: $$\sum_{n=1}^\infty a_nb_n \leq \left( \sum_{n=1}^\infty a_n^2 \right)^{1/2} \left( \sum_{n=1}^\infty b_n^2 \right)^{1/2}$$  but it's not useful here. ls -la symbolics... what does that last symbol mean? Can I use a present-tense verb when writing about a past event? Enabling CORS in GeoServer (jetty)? Usually in the morning I brush my teeth after breakfast. But my dentist told me that it's better not brush them right after eating food, because eating makes them soft.  So now I brush my teeth before breakfast. Is this the correct procedure?  PS. Just found , the author has the same opinion.  Just want to get a additional confirmation. What's the fastest way to find mineshafts? , and one place I'm fairly sure I can find them is a mineshaft.  Which leaves me back at square one, how do I find a mine shaft?  It seems they were made substantially harder to find between 1.8 and 1.0.  What's the fastest way to find a mineshaft? How can I programmatically pause an NSTimer? I'm using an NSTimer to do some rendering in an OpenGL based iPhone app.  I have a modal dialog box that pops up and requests user input.  While the user is providing input I'd like to "pause" i.e. something like this:  [myNSTimer pause];   I'm using this syntax because I've been doing things like:  [myNSTimer invalidate];   when I want it to stop.  How can I programmatically pause the NSTimer? How do I get a Cron like scheduler in Python? Does timbre consist in pitch and volume? I read that the physical properties of a sound wave correspond to its audible qualities: pitch, volume, and timbre. However, an oscilloscope uses only two-dimensions to accurately depict the physical properties of a wave. Intuitively, pitch and volume seem more basic than timbre does, so I surmise that timbre must consist in those two properties.    Does timbre consist in those two properties? How do two-dimensional waveform diagrams depict three properties of sound waves? How to run untrusted Ruby code inside a safe sandbox? Are there gotchas using varargs with reference parameters I have this piece of code (summarized)...  AnsiString working(AnsiString format,...) {     va_list argptr;     AnsiString buff;      va_start(argptr, format);     buff.vprintf(format.c_str(), argptr);      va_end(argptr);     return buff; }   And, on the basis that pass by reference is preferred where possible, I changed it thusly.  AnsiString broken(const AnsiString &amp;format,...) { ... the rest, totally identical ... }   My calling code is like this:-  AnsiString s1, s2;     s1 = working("Hello %s", "World");     s2 = broken("Hello %s", "World");   But, s1 contains "Hello World", while s2 has "Hello (null)". I think this is due to the way va_start works, but I'm not exactly sure what's going on. How many switches can be stacked/interconnected? The context for my question might be a bit strange.   I have stuttering and therefore I have some difficulties pronouncing some words starting with particular phonetics. And I've found that if a sentence starts with a /th/ sound, it makes me feel uncomfortable.  Especially in the word is "thanks" or "thank you".  So I want to know if there's a popular alternative for "thank you" that may not seem strange and that unnatural. I've searched the website and I know there are alternatives like "I appreciate your help." but that sounds a bit overly formal for me. (Or is it? correct me if I'm mistaken.) SBS 2011 - Is Store.exe High Memory Usage Normal? How to raise a complex number to the power of another complex number? How do I calculate the outcome of taking one complex number to the power of another, ie  $\displaystyle {(a + bi)}^{(c + di)}$? How much of an $n$-dimensional manifold can we embed into $\mathbb{R}^n$? I observed some naive examples. Spheres, for example, when we cut out one point, can be embedded into $\mathbb{R}^n$. And if we cut out a measure zero set of a projective space, it can be embedded into the Euclidean space of the same dimension. So I wonder if all manifolds can be embedded into a same dimensional Euclidean space when we cut out a measure zero set? Can anyone prove it or disprove it by giving me some counterexamples? Positive integer multiples of an irrational mod 1 are dense I'm not sure how to solve this one. Thank you!  $2.$ For any $\alpha\in \mathbb R$ we define $$\lfloor \alpha \rfloor = \max_{n\in\mathbb Z}\{\,n\mid n\leq \alpha\,\}$$ and $$\alpha\bmod 1 = \alpha - \lfloor \alpha \rfloor$$ Let $\alpha$ be irrational. (a) Given $n\in\mathbb N$ show that $\{\,k\alpha\bmod1\mid k\in\mathbb N\,\}\cap\left[0,\frac{1}{n}\right]\neq\emptyset$ (b) Prove that $\{\,n\alpha\bmod 1\mid n\in\mathbb N\,\}$ is dense in $[0,1]$.