2014-01-24 17 views
2

我想实现一个喷口作为套接字监听器。要检查如何在暴风雨阻挡过程的工作,我Scanner.in WordCounter例子的喷口为folows风暴水嘴中的阻塞过程

public void nextTuple() { 
     /** 
     * The nextuple it is called forever, so if we have been readed the file 
     * we will wait and then return 
     */ 
     Scanner scanner=new Scanner(System.in); 
     scanner.next(); 

     /* Code to read from file */ 

    } 

当我尝试运行此出现了一些错误。如果我删除扫描程序代码,该示例运行良好。有人能告诉我如何在风暴中处理阻塞流程?

+1

什么是错误? – Chiron

回答

3

风暴在发射元组时使用的主要方法是nextTuple。所有喷口方法都由同一个线程调用。如果在nextTuple中有任何块,喷口将无法发送心跳以确保其存活。因此,我建议你使用无阻塞功能。