Java 使用twitter4j在运行时添加位置过滤器

Java 使用twitter4j在运行时添加位置过滤器,java,twitter,twitter-hbc,Java,Twitter,Twitter Hbc,我使用twitter4j从twitter中获得一个按位置过滤的流,使用以下方法: List<Location> locations = new ArrayList<>; StatusesFilterEndpoint endpoint.locations(locations); BasicClient client = new ClientBuilder() .name(NAME) .hosts(Co

我使用twitter4j从twitter中获得一个按位置过滤的流,使用以下方法:

    List<Location> locations = new ArrayList<>;

    StatusesFilterEndpoint endpoint.locations(locations);
    BasicClient client = new ClientBuilder()
            .name(NAME)
            .hosts(Constants.STREAM_HOST)
            .endpoint(endpoint)
            .authentication(auth)
            .processor(new StringDelimitedProcessor(rowTweet))
            .build(); 
   client.connect();


   while (isConnected()) {
                String rowtweet = rowTweet.poll(5, TimeUnit.SECONDS);
                if (rowtweet != null) {
                    Status status = DataObjectFactory.createStatus(rowtweet);
                    statusQueue.put(status);
                }
            }
此例外情况:

 public void addLocation(Location target) throws InterruptedException, TwitterException        {
    locations.add(target);
    endpoint.locations(locations);
    connect();
} 
java.lang.IllegalStateException: There is already a connection thread running for TweetsByLocationStream, endpoint: /1.1/statuses/filter.json?delimited=length&stall_warnings=true
        at com.twitter.hbc.httpclient.BasicClient.connect(BasicClient.java:98)
        at com.newsry.streams.TweetsByLocationStream.connect(TweetsByLocationStream.java:77)
        at com.newsry.streams.TweetsByLocationStream.addLocation(TweetsByLocationStream.java:129)
        at com.newsry.engine.NewsryEngine.addLocation(NewsryEngine.java:183)
        at com.newsry.streams.LocationStreamTest.main(LocationStreamTest.java:44)

您只需停止推特流,并通过添加或删除所需的位置来更改您的
过滤器查询
。然后需要重新启动推特流。它几乎是运行时,但它工作(它是在非常小的时间间隔内完成的,因此您不会丢失
twitter4j
流式处理结果)。

您是否尝试过先停止(),然后添加位置(),最后连接()或重新连接()?谢谢,但这是我已经做过的,停止()然后添加位置(),然后重新连接(),失败了,我尝试在没有stop()的情况下添加位置,它工作正常,我将使用正确的代码重播。