arrays - Exception in thread "Thread-2" java.lang.NullPointerException.error in my code -
I had to work my code (at least to some extent) and I would have to change something, because it will not launch now . No error has been shown within the code, but it appears when I try to run it:
Exception in thread "thread-2" java.lang.NullPointerException at azsystem3 .Add.run (Java.lang.Thread.run at (.Java: 662)
and (main.java:57) this line is: sum.s + = A [i];
How do I fix this? Here is my relevant code:
package azsystem3; Import java.util. *; Import java.util.concurrent.locks .Lock; Import java.util.concurrent.locks.ReentrantLock; Playable filling tool {int [] a; Fixed Random B = New random (int); int start; intent; fill public (int [] a, int start, int end) {this.a = a; this.start = start; this.end = end;} public zero run (For (int i = this.start; i & lt; this.end; i ++) {a [i] = b.nextInt (100);}}} class values {ints;} classes apply Make Runnabel {value sum; L lock; integer [] a; int start; intent; // public long zodiac = 0; add public (int [] a, int start, int end, lock l, value s) {this .l = l; This.start = start; This.end = end; Yoga = s; } Run Public Zero () {int i; For (i = start; i
Any suggestions?
Thread-security is not only running in your code ()
-method Locking is required, but you should also make your own personal class as sum
member, last otherwise a thread A complete initial object of type value
can not be found, where sum
-member still null
.
And note: Try to follow standard Java code conventions for better readability.
Another overview, for this code
(i = start; i
:
for (i = start; i
I do not believe in any thread safety because improper handling of brackets and therefore locking.
Comments
Post a Comment