小编xDr*_*nik的帖子

Twitter4j TwitterStream或BufferReading导致java.lang.OutOfMemoryError:Java堆空间

这是我的第一篇Stackoverflow帖子,对不起,如果不是很好的话.反馈肯定会有所帮助!

我目前正在java.lang.OutOfMemoryError: Java Heap space使用Twitter Streaming API处理项目问题.

在大约500 - 1000条推文中流式传输之后出现错误,我无法确定导致它发生的原因.

在我的onStatus方法中StatusListener我有以下代码:

public void onStatus(Status status) {

        tweetCount++;
        System.out.println("Tweet #" + tweetCount);

        String statusInfo = status.getText().replaceAll("\n", "").replaceAll("\r", "");

        String usersCountry = getTweetUserLocation(status);
        status = null;

        if(!usersCountry.equals("INVALID_LOCATION")){
           countryList.updateWhoTalkedAboutWho(usersCountry, statusInfo);
        }

        try {
           Thread.sleep(1000);
        } catch (InterruptedException e) {
           // TODO Auto-generated catch block
           System.out.println("Exception in onStatus() catch block");
           e.printStackTrace();
        }
     }
Run Code Online (Sandbox Code Playgroud)

错误可能是由状态进入的速度引起的吗?我可以理解为什么如果状态比处理速度快得多,它会占用更多内存.

另一个嫌疑人是BufferReader,这里是代码:

URL url = new URL(urlStr);
URLConnection conn = url.openConnection();

BufferedReader rd …
Run Code Online (Sandbox Code Playgroud)

java memory-leaks heap-memory twitter4j

6
推荐指数
1
解决办法
1589
查看次数

Laravel Auth :: attempt()总是假的?

我最近开始学习Laravel(PHP MVC框架),我在使用以下方式验证用户时遇到了很多问题:Auth :: attempt($ credentials).

我将把我的代码片段放在下面.在我的mySQL数据库中,我有一个记录,其中包含以下key => values:id => 1,username =>'admin',password =>'admin',created_at => 0000-00-00 00:00:00,updated_at => 0000-00-00 00:00:00

验证器通过,但Auth:尝试总是失败.

如果下面的代码和我的小解释还不够,请告诉我!:-)

routes.php文件:

Route::get('login', 'AuthController@showLogin');
Route::post('login', 'AuthController@postLogin');
Run Code Online (Sandbox Code Playgroud)

AuthController:

public function showLogin(){

    if(Auth::check()){
        //Redirect to their home page
    }
    //Not logged in
    return View::make('auth/login');
}

public function postLogin(){

    $userData = array(
        'username' => Input::get('username'),
        'password' => Input::get('password')
    );

    $reqs = array(
        'username' => 'Required',
        'password' => 'Required'
    );

    $validator = Validator::make($userData, $reqs);

    if($validator->passes() && Auth::attempt($userData)){
        return Redirect::to('home');
    }
    return Redirect::to('login')->withInput(Input::except('password'));
}
Run Code Online (Sandbox Code Playgroud)

php authentication laravel

5
推荐指数
1
解决办法
7458
查看次数