List of usage examples for java.lang Thread start
public synchronized void start()
From source file:com.test.database.jedis.TestJedisEvalLua.java
public static void generateTestData() throws InterruptedException { Jedis jedis = new Jedis(host, port); jedis.flushAll();//from w w w . j a v a 2 s . com jedis.close(); final CountDownLatch latch = new CountDownLatch(threadCount); for (int i = 0; i < threadCount; ++i) { final int temp = i; Thread thread = new Thread() { public void run() { Jedis jedis = new Jedis(host, port); int per = honBaoCount / threadCount; JSONObject object = new JSONObject(); for (int j = temp * per; j < (temp + 1) * per; j++) { object.put("id", j); object.put("money", j); jedis.lpush(hongBaoList, object.toString()); } latch.countDown(); jedis.close(); } }; thread.start(); } latch.await(); }
From source file:net.sf.sahi.util.Utils.java
public static String executeCommand(String[] command) throws Exception { StringBuffer sb = new StringBuffer(); Process p = Runtime.getRuntime().exec(command); InputStream stdInput = p.getInputStream(); InputStream stdError = p.getErrorStream(); StringBuffer inBuffer = new StringBuffer(); StringBuffer errBuffer = new StringBuffer(); Thread inThread = new Thread(new StreamReader(stdInput, inBuffer)); inThread.start(); Thread errThread = new Thread(new StreamReader(stdError, errBuffer)); errThread.start();// w w w.ja va 2 s . com p.waitFor(); inThread.join(); errThread.join(); sb.append(inBuffer); sb.append(errBuffer); return sb.toString(); }
From source file:com.cooliris.mediayemaha.UriTexture.java
public static final Bitmap createFromUri(Context context, String uri, int maxResolutionX, int maxResolutionY, long cacheId, ClientConnectionManager connectionManager) throws IOException, URISyntaxException, OutOfMemoryError { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false;//from w ww.jav a2 s . c o m options.inPreferredConfig = Bitmap.Config.RGB_565; options.inDither = true; long crc64 = 0; Bitmap bitmap = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT)) { // We need the filepath for the given content uri crc64 = cacheId; } else { crc64 = Utils.Crc64Long(uri); } bitmap = createFromCache(crc64, maxResolutionX); if (bitmap != null) { return bitmap; } final boolean local = uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith("file://"); // Get the input stream for computing the sample size. BufferedInputStream bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Compute the sample size, i.e., not decoding real pixels. if (bufferedInput != null) { options.inSampleSize = computeSampleSize(bufferedInput, maxResolutionX, maxResolutionY); } else { return null; } // Get the input stream again for decoding it to a bitmap. bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Decode bufferedInput to a bitmap. if (bufferedInput != null) { options.inDither = false; options.inJustDecodeBounds = false; Thread timeoutThread = new Thread("BitmapTimeoutThread") { public void run() { try { Thread.sleep(6000); options.requestCancelDecode(); } catch (InterruptedException e) { } } }; timeoutThread.start(); bitmap = BitmapFactory.decodeStream(bufferedInput, null, options); } if ((options.inSampleSize > 1 || !local) && bitmap != null) { writeToCache(crc64, bitmap, maxResolutionX / options.inSampleSize); } return bitmap; }
From source file:Main.java
public static void GetSUAccess() { Thread su = new Thread(new Thread() { public void run() { try { Log.i("SU", "Trying to grant access to port..."); Process suProcess = Runtime.getRuntime().exec("su"); DataOutputStream os = new DataOutputStream(suProcess.getOutputStream()); if (null != os) { os.writeBytes("chmod 666 /dev/ttymxc1 \n"); os.flush();/*ww w .ja va2s . c o m*/ } Log.i("SU", "Granted Access to Port"); } catch (IOException e) { Log.e("SU", "Grant SuperUser Access Failed"); } } }); su.start(); }
From source file:io.fabric8.tooling.archetype.generator.ArchetypeTest.java
@AfterClass public static void afterAll() throws Exception { // now let invoke the projects final int[] resultPointer = new int[1]; StringWriter sw = new StringWriter(); Set<String> modules = new HashSet<String>(); for (final String outDir : outDirs) { String module = new File(outDir).getName(); if (modules.add(module)) { sw.append(String.format(" <module>%s</module>\n", module)); }//from ww w . ja v a 2 s .co m } sw.close(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(ArchetypeTest.class.getResourceAsStream("/archetypes-test-pom.xml"), baos); String pom = new String(baos.toByteArray()).replace(" <!-- to be replaced -->", sw.toString()); FileWriter modulePom = new FileWriter("target/archetypes-test-pom.xml"); IOUtils.copy(new StringReader(pom), modulePom); modulePom.close(); final String outDir = new File("target").getCanonicalPath(); // thread locals are evil (I'm talking to you - org.codehaus.plexus.DefaultPlexusContainer#lookupRealm!) Thread t = new Thread(new Runnable() { @Override public void run() { System.out.println("Invoking projects in " + outDir); MavenCli maven = new MavenCli(); resultPointer[0] = maven.doMain( new String[] { "clean", "package", "-f", "archetypes-test-pom.xml" }, outDir, System.out, System.out); System.out.println("result: " + resultPointer[0]); } }); t.start(); t.join(); assertEquals("Build of project " + outDir + " failed. Result = " + resultPointer[0], 0, resultPointer[0]); }
From source file:vn.mbm.phimp.me.gallery3d.media.UriTexture.java
public static final Bitmap createFromUri(Context context, String uri, int maxResolutionX, int maxResolutionY, long cacheId, ClientConnectionManager connectionManager) throws IOException, URISyntaxException, OutOfMemoryError { Log.i(TAG, "creatFromUri()"); Log.i(TAG, "URI: " + uri); final BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false;/* ww w . j a v a 2s .co m*/ options.inPreferredConfig = Bitmap.Config.RGB_565; options.inDither = true; long crc64 = 0; Bitmap bitmap = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT)) { // We need the filepath for the given content uri crc64 = cacheId; } else { crc64 = Utils.Crc64Long(uri); } bitmap = createFromCache(crc64, maxResolutionX); if (bitmap != null) { return bitmap; } final boolean local = uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith("file://"); // Get the input stream for computing the sample size. BufferedInputStream bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Compute the sample size, i.e., not decoding real pixels. if (bufferedInput != null) { options.inSampleSize = computeSampleSize(bufferedInput, maxResolutionX, maxResolutionY); } else { return null; } // Get the input stream again for decoding it to a bitmap. bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Decode bufferedInput to a bitmap. if (bufferedInput != null) { options.inDither = false; options.inJustDecodeBounds = false; Thread timeoutThread = new Thread("BitmapTimeoutThread") { public void run() { try { Thread.sleep(6000); options.requestCancelDecode(); } catch (InterruptedException e) { } } }; timeoutThread.start(); bitmap = BitmapFactory.decodeStream(bufferedInput, null, options); } if ((options.inSampleSize > 1 || !local) && bitmap != null) { writeToCache(crc64, bitmap, maxResolutionX / options.inSampleSize); } return bitmap; }
From source file:prince.app.sphotos.Gallery.UriTexture.java
public static final Bitmap createFromUri(Context context, String uri, int maxResolutionX, int maxResolutionY, long cacheId, ClientConnectionManager connectionManager) throws IOException, URISyntaxException, OutOfMemoryError { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false;//from w ww .j a v a 2 s.co m options.inPreferredConfig = Bitmap.Config.RGB_565; options.inDither = true; long crc64 = 0; Bitmap bitmap = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT)) { // We need the filepath for the given content uri crc64 = cacheId; } else { crc64 = Utils.Crc64Long(uri); } bitmap = createFromCache(crc64, maxResolutionX); if (bitmap != null) { Log.i(TAG, "!!! Bitmap in cache !!!"); return bitmap; } final boolean local = uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith("file://"); // Get the input stream for computing the sample size. BufferedInputStream bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Compute the sample size, i.e., not decoding real pixels. if (bufferedInput != null) { options.inSampleSize = computeSampleSize(bufferedInput, maxResolutionX, maxResolutionY); } else { return null; } // Get the input stream again for decoding it to a bitmap. bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Decode bufferedInput to a bitmap. if (bufferedInput != null) { options.inDither = false; options.inJustDecodeBounds = false; Thread timeoutThread = new Thread("BitmapTimeoutThread") { public void run() { try { Thread.sleep(6000); options.requestCancelDecode(); } catch (InterruptedException e) { } } }; timeoutThread.start(); bitmap = BitmapFactory.decodeStream(bufferedInput, null, options); } if ((options.inSampleSize > 1 || !local) && bitmap != null) { // writeToCache(crc64, bitmap, maxResolutionX / options.inSampleSize); writeToCache(crc64, bitmap, maxResolutionX); } return bitmap; }
From source file:com.ocp.media.UriTexture.java
public static final Bitmap createFromUri(Context context, String uri, int maxResolutionX, int maxResolutionY, long cacheId, ClientConnectionManager connectionManager) throws IOException, URISyntaxException, OutOfMemoryError { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false;//from w w w .jav a 2 s . co m options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inDither = true; long crc64 = 0; Bitmap bitmap = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT)) { // We need the filepath for the given content uri crc64 = cacheId; } else { crc64 = Utils.Crc64Long(uri); } bitmap = createFromCache(crc64, maxResolutionX); if (bitmap != null) { return bitmap; } final boolean local = uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith("file://"); // Get the input stream for computing the sample size. BufferedInputStream bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Compute the sample size, i.e., not decoding real pixels. if (bufferedInput != null) { options.inSampleSize = computeSampleSize(bufferedInput, maxResolutionX, maxResolutionY); } else { return null; } // Get the input stream again for decoding it to a bitmap. bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Decode bufferedInput to a bitmap. if (bufferedInput != null) { options.inDither = false; options.inJustDecodeBounds = false; Thread timeoutThread = new Thread("BitmapTimeoutThread") { public void run() { try { Thread.sleep(6000); options.requestCancelDecode(); } catch (InterruptedException e) { } } }; timeoutThread.start(); bitmap = BitmapFactory.decodeStream(bufferedInput, null, options); } if ((options.inSampleSize > 1 || !local) && bitmap != null) { writeToCache(crc64, bitmap, maxResolutionX / options.inSampleSize); } return bitmap; }
From source file:com.igormaznitsa.sciareto.ui.UiUtils.java
public static void openInSystemViewer(@Nonnull final File file) { final Runnable startEdit = new Runnable() { @Override//from w w w . j a v a2s . c om public void run() { boolean ok = false; if (Desktop.isDesktopSupported()) { final Desktop dsk = Desktop.getDesktop(); if (dsk.isSupported(Desktop.Action.OPEN)) { try { dsk.open(file); ok = true; } catch (Throwable ex) { LOGGER.error("Can't open file in system viewer : " + file, ex);//NOI18N } } } if (!ok) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { DialogProviderManager.getInstance().getDialogProvider() .msgError("Can't open file in system viewer! See the log!");//NOI18N Toolkit.getDefaultToolkit().beep(); } }); } } }; final Thread thr = new Thread(startEdit, " MMDStartFileEdit");//NOI18N thr.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(final Thread t, final Throwable e) { LOGGER.error("Detected uncaught exception in openInSystemViewer() for file " + file, e); } }); thr.setDaemon(true); thr.start(); }
From source file:com.cooliris.media.UriTexture.java
public static final Bitmap createFromUri(Context context, String uri, int maxResolutionX, int maxResolutionY, long cacheId, ClientConnectionManager connectionManager) throws IOException, URISyntaxException, OutOfMemoryError { final BitmapFactory.Options options = new BitmapFactory.Options(); options.inScaled = false;/*from w w w . j av a 2 s. com*/ options.inPreferredConfig = Bitmap.Config.ARGB_8888; options.inDither = true; long crc64 = 0; Bitmap bitmap = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT)) { // We need the filepath for the given content uri crc64 = cacheId; } else { crc64 = Utils.Crc64Long(uri); } bitmap = createFromCache(crc64, maxResolutionX); if (bitmap != null) { return bitmap; } final boolean local = uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith("file://"); // Get the input stream for computing the sample size. BufferedInputStream bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Compute the sample size, i.e., not decoding real pixels. if (bufferedInput != null) { options.inSampleSize = computeSampleSize(bufferedInput, maxResolutionX, maxResolutionY); } else { return null; } // Get the input stream again for decoding it to a bitmap. bufferedInput = null; if (uri.startsWith(ContentResolver.SCHEME_CONTENT) || uri.startsWith(ContentResolver.SCHEME_FILE)) { // Get the stream from a local file. bufferedInput = new BufferedInputStream(context.getContentResolver().openInputStream(Uri.parse(uri)), 16384); } else { // Get the stream from a remote URL. bufferedInput = createInputStreamFromRemoteUrl(uri, connectionManager); } // Decode bufferedInput to a bitmap. if (bufferedInput != null) { options.inDither = false; options.inJustDecodeBounds = false; options.inPurgeable = true; Thread timeoutThread = new Thread("BitmapTimeoutThread") { public void run() { try { Thread.sleep(6000); options.requestCancelDecode(); } catch (InterruptedException e) { } } }; timeoutThread.start(); bitmap = BitmapFactory.decodeStream(bufferedInput, null, options); } if (bitmap != null) { bitmap = Utils.resizeBitmap(bitmap, maxResolutionX); } if ((options.inSampleSize > 1 || !local) && bitmap != null) { writeToCache(crc64, bitmap, maxResolutionX); } return bitmap; }