public

android Charset.availableCharsets() crash test

  • Download Gist
And_charset_comparisonActivity.java
Java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
package kr.pe.kingori.exp.charset;
 
import java.nio.charset.Charset;
import java.util.concurrent.atomic.AtomicInteger;
 
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.TextView;
 
public class And_charset_comparisonActivity extends Activity {
private static final String LOG_TAG = "charset";
Handler handler = new Handler();
AtomicInteger count = new AtomicInteger(1);
 
Runnable charsetRunnable = new Runnable() {
@Override
public void run() {
try {
Log.d(LOG_TAG, "And_charset_comparisonActivity.run: " + count.incrementAndGet());
Charset.availableCharsets();
} catch (Throwable e) {
Log.w("log", "And_charset_comparisonActivity.AvailableCharsetRunnable.run:", e);
}
}
};
 
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
checkTime();
}
 
private void checkTime() {
long startTime = System.nanoTime();
for (int i = 0; i < 10; i++) {
Charset.availableCharsets();
}
long endTime = System.nanoTime();
((TextView) findViewById(R.id.time_result)).setText(Long.toString((endTime - startTime) / 1000 / 1000));
}
 
public void onExecuteThreads(View v) {
for (int i = 0; i < 5; i++) {
new Thread(charsetRunnable).start();
}
 
handler.postDelayed(new Runnable() {
@Override
public void run() {
onExecuteThreads(null);
}
}, 500);
 
}
 
}
main.xml
XML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
 
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
 
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Charset.availableCharsets() * 10 times"
android:textAppearance="?android:attr/textAppearanceLarge" />
 
<TextView
android:id="@+id/time_result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
 
<Button
android:id="@+id/thread_run"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Run"
android:onClick="onExecuteThreads" />
</LinearLayout>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.