Class: Bio::MAF::JThreadRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/bio/maf/jobs.rb

Instance Method Summary collapse

Constructor Details

#initialize(n_parallel) ⇒ JThreadRunner

Returns a new instance of JThreadRunner.



77
78
79
80
81
82
# File 'lib/bio/maf/jobs.rb', line 77

def initialize(n_parallel)
  @n_parallel = n_parallel
  @exec = java.util.concurrent.Executors.newFixedThreadPool(n_parallel)
  @ecs = java.util.concurrent.ExecutorCompletionService.new(@exec)
  @n = 0
end

Instance Method Details

#add(&blk) ⇒ Object



84
85
86
87
# File 'lib/bio/maf/jobs.rb', line 84

def add(&blk)
  @ecs.submit(&blk)
  @n += 1
end

#runObject



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/bio/maf/jobs.rb', line 89

def run
  seen = 0
  until seen == @n
    f = @ecs.take()
    begin
      f.get()
    rescue Exception => e
      LOG.error e
      @exec.shutdownNow()
      raise
    end
    seen += 1
  end
  @exec.shutdown()
end