Skip to content

Instantly share code, notes, and snippets.

@kingori
Created June 14, 2012 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kingori/2927754 to your computer and use it in GitHub Desktop.
Save kingori/2927754 to your computer and use it in GitHub Desktop.
android Charset.availableCharsets() crash test
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);
}
}
<?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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment