mercredi 10 février 2016

Threading in Java 8

I am trying to find some Java8 tutorial. Right now i am reading from a file, creating a map and then read from a second file and generate the result after matching its values from the file1 map. Its a simple program, but i have to tackle large input i.e., when the size of both inputs is large.

My logic is

  • Check the file size, if its considerably large then use stream to read the file and generate N number of sub-files (of considerable size)
  • Now create N threads. Each individual thread would know that it has particular file to read i.e., T1 would read F1, T2 would read F2
  • Now use stream to read the second file, pass it's each input (JSON Object) to subsequent threads, once each thread reach a limit of lets say 1000 objects, they will compare them with its thread respective file.

In theory, it looks good. But I have never worked on multi-threads application let alone using Java8 threads. All the tutorials that i looked for are mixing lambda expressions with threads. I just need basic stuff.

Here is what pointers i am trying to find

  • Java8 specific threading modal, perhaps some design pattern as well
  • How can tell each thread which file it should monitor ?
  • How can i pass information from main thread (which is reading from other file) to sub-threads (array of threads ?)
  • How can the result of each thread could be merged into one result ?

Aucun commentaire:

Enregistrer un commentaire