cannot invoke stream() on the primitive type void while doing —...
up vote
-1
down vote
favorite
I was trying to implement a java program to read a huge file simultaneously by 100 threads.
So I am dividing my file in 100 chunks and giving it to 100 threads.
And at the end I want to calculate the capacity of each chunk and and print the total capacity read by all threads.
Below is my code...
And I am getting errors in my code and I am not able to fix it. I am new to concurrency and Multithreading .Please help me to understand and fix this issue.
public class CustomRecursiveTaskToReadHugeFile extends RecursiveTask {
static volatile boolean flag;
File file;
FileChannel fc;
BlockingQueue<Integer> bq;
public CustomRecursiveTaskToReadHugeFile(boolean flag, File file, FileChannel c) {
super();
this.flag = flag;
this.file = file;
this.fc = c;
}
@Override
protected Integer compute() {
if (!flag) {
return ForkJoinTask.invokeAll(createSubtasks()).stream().mapToInt(ForkJoinTask::join).sum(); // Here is the problem area
} else
processFiles();
}
private Collection<CustomRecursiveTaskToReadHugeFile> createSubtasks() {
List<CustomRecursiveTaskToReadHugeFile> cl = new ArrayList<CustomRecursiveTaskToReadHugeFile>();
if (!flag) {
FileInputStream is = null;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
FileChannel c = is.getChannel();
for (long i = 0; i < 1000000; i = i + 100) {
try {
c.position(i);
cl.add(new CustomRecursiveTaskToReadHugeFile(flag, file, c));
} catch (IOException e) {
e.printStackTrace();
}
}
}
return cl;
}
private Integer processFiles() {
ByteBuffer dst = null;
for (int i = 0; i < 00; i++) {
try {
fc.read(dst, i);
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(" Current thread capacity is " + dst.capacity());
try {
bq.put( new Integer(dst.capacity()));
} catch (InterruptedException e) {
e.printStackTrace();
}
return new Integer(dst.capacity());
}
}
java multithreading concurrency fork-join
add a comment |
up vote
-1
down vote
favorite
I was trying to implement a java program to read a huge file simultaneously by 100 threads.
So I am dividing my file in 100 chunks and giving it to 100 threads.
And at the end I want to calculate the capacity of each chunk and and print the total capacity read by all threads.
Below is my code...
And I am getting errors in my code and I am not able to fix it. I am new to concurrency and Multithreading .Please help me to understand and fix this issue.
public class CustomRecursiveTaskToReadHugeFile extends RecursiveTask {
static volatile boolean flag;
File file;
FileChannel fc;
BlockingQueue<Integer> bq;
public CustomRecursiveTaskToReadHugeFile(boolean flag, File file, FileChannel c) {
super();
this.flag = flag;
this.file = file;
this.fc = c;
}
@Override
protected Integer compute() {
if (!flag) {
return ForkJoinTask.invokeAll(createSubtasks()).stream().mapToInt(ForkJoinTask::join).sum(); // Here is the problem area
} else
processFiles();
}
private Collection<CustomRecursiveTaskToReadHugeFile> createSubtasks() {
List<CustomRecursiveTaskToReadHugeFile> cl = new ArrayList<CustomRecursiveTaskToReadHugeFile>();
if (!flag) {
FileInputStream is = null;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
FileChannel c = is.getChannel();
for (long i = 0; i < 1000000; i = i + 100) {
try {
c.position(i);
cl.add(new CustomRecursiveTaskToReadHugeFile(flag, file, c));
} catch (IOException e) {
e.printStackTrace();
}
}
}
return cl;
}
private Integer processFiles() {
ByteBuffer dst = null;
for (int i = 0; i < 00; i++) {
try {
fc.read(dst, i);
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(" Current thread capacity is " + dst.capacity());
try {
bq.put( new Integer(dst.capacity()));
} catch (InterruptedException e) {
e.printStackTrace();
}
return new Integer(dst.capacity());
}
}
java multithreading concurrency fork-join
1
invokeAll
return type isvoid
. You can't call a method (.stream()
in your case) onvoid
.
– Kartik
yesterday
hi Kartik, ForkJoinTask.invokeAll(createSubtasks()).stream() - > here I am calling stream on returned List of createSubtasks()) ..
– Rama Tripathi
19 hours ago
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
I was trying to implement a java program to read a huge file simultaneously by 100 threads.
So I am dividing my file in 100 chunks and giving it to 100 threads.
And at the end I want to calculate the capacity of each chunk and and print the total capacity read by all threads.
Below is my code...
And I am getting errors in my code and I am not able to fix it. I am new to concurrency and Multithreading .Please help me to understand and fix this issue.
public class CustomRecursiveTaskToReadHugeFile extends RecursiveTask {
static volatile boolean flag;
File file;
FileChannel fc;
BlockingQueue<Integer> bq;
public CustomRecursiveTaskToReadHugeFile(boolean flag, File file, FileChannel c) {
super();
this.flag = flag;
this.file = file;
this.fc = c;
}
@Override
protected Integer compute() {
if (!flag) {
return ForkJoinTask.invokeAll(createSubtasks()).stream().mapToInt(ForkJoinTask::join).sum(); // Here is the problem area
} else
processFiles();
}
private Collection<CustomRecursiveTaskToReadHugeFile> createSubtasks() {
List<CustomRecursiveTaskToReadHugeFile> cl = new ArrayList<CustomRecursiveTaskToReadHugeFile>();
if (!flag) {
FileInputStream is = null;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
FileChannel c = is.getChannel();
for (long i = 0; i < 1000000; i = i + 100) {
try {
c.position(i);
cl.add(new CustomRecursiveTaskToReadHugeFile(flag, file, c));
} catch (IOException e) {
e.printStackTrace();
}
}
}
return cl;
}
private Integer processFiles() {
ByteBuffer dst = null;
for (int i = 0; i < 00; i++) {
try {
fc.read(dst, i);
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(" Current thread capacity is " + dst.capacity());
try {
bq.put( new Integer(dst.capacity()));
} catch (InterruptedException e) {
e.printStackTrace();
}
return new Integer(dst.capacity());
}
}
java multithreading concurrency fork-join
I was trying to implement a java program to read a huge file simultaneously by 100 threads.
So I am dividing my file in 100 chunks and giving it to 100 threads.
And at the end I want to calculate the capacity of each chunk and and print the total capacity read by all threads.
Below is my code...
And I am getting errors in my code and I am not able to fix it. I am new to concurrency and Multithreading .Please help me to understand and fix this issue.
public class CustomRecursiveTaskToReadHugeFile extends RecursiveTask {
static volatile boolean flag;
File file;
FileChannel fc;
BlockingQueue<Integer> bq;
public CustomRecursiveTaskToReadHugeFile(boolean flag, File file, FileChannel c) {
super();
this.flag = flag;
this.file = file;
this.fc = c;
}
@Override
protected Integer compute() {
if (!flag) {
return ForkJoinTask.invokeAll(createSubtasks()).stream().mapToInt(ForkJoinTask::join).sum(); // Here is the problem area
} else
processFiles();
}
private Collection<CustomRecursiveTaskToReadHugeFile> createSubtasks() {
List<CustomRecursiveTaskToReadHugeFile> cl = new ArrayList<CustomRecursiveTaskToReadHugeFile>();
if (!flag) {
FileInputStream is = null;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
FileChannel c = is.getChannel();
for (long i = 0; i < 1000000; i = i + 100) {
try {
c.position(i);
cl.add(new CustomRecursiveTaskToReadHugeFile(flag, file, c));
} catch (IOException e) {
e.printStackTrace();
}
}
}
return cl;
}
private Integer processFiles() {
ByteBuffer dst = null;
for (int i = 0; i < 00; i++) {
try {
fc.read(dst, i);
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println(" Current thread capacity is " + dst.capacity());
try {
bq.put( new Integer(dst.capacity()));
} catch (InterruptedException e) {
e.printStackTrace();
}
return new Integer(dst.capacity());
}
}
java multithreading concurrency fork-join
java multithreading concurrency fork-join
edited 19 hours ago
asked yesterday
Rama Tripathi
419
419
1
invokeAll
return type isvoid
. You can't call a method (.stream()
in your case) onvoid
.
– Kartik
yesterday
hi Kartik, ForkJoinTask.invokeAll(createSubtasks()).stream() - > here I am calling stream on returned List of createSubtasks()) ..
– Rama Tripathi
19 hours ago
add a comment |
1
invokeAll
return type isvoid
. You can't call a method (.stream()
in your case) onvoid
.
– Kartik
yesterday
hi Kartik, ForkJoinTask.invokeAll(createSubtasks()).stream() - > here I am calling stream on returned List of createSubtasks()) ..
– Rama Tripathi
19 hours ago
1
1
invokeAll
return type is void
. You can't call a method (.stream()
in your case) on void
.– Kartik
yesterday
invokeAll
return type is void
. You can't call a method (.stream()
in your case) on void
.– Kartik
yesterday
hi Kartik, ForkJoinTask.invokeAll(createSubtasks()).stream() - > here I am calling stream on returned List of createSubtasks()) ..
– Rama Tripathi
19 hours ago
hi Kartik, ForkJoinTask.invokeAll(createSubtasks()).stream() - > here I am calling stream on returned List of createSubtasks()) ..
– Rama Tripathi
19 hours ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404606%2fcannot-invoke-stream-on-the-primitive-type-void-while-doing-forkjointask-i%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
invokeAll
return type isvoid
. You can't call a method (.stream()
in your case) onvoid
.– Kartik
yesterday
hi Kartik, ForkJoinTask.invokeAll(createSubtasks()).stream() - > here I am calling stream on returned List of createSubtasks()) ..
– Rama Tripathi
19 hours ago