• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ThreadPolicy类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中android.os.StrictMode.ThreadPolicy的典型用法代码示例。如果您正苦于以下问题:Java ThreadPolicy类的具体用法?Java ThreadPolicy怎么用?Java ThreadPolicy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ThreadPolicy类属于android.os.StrictMode包,在下文中一共展示了ThreadPolicy类的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: newThread

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
@Override
public synchronized Thread newThread(@NonNull Runnable runnable) {
  final Thread result = new Thread(runnable, "glide-" + name + "-thread-" + threadNum) {
    @Override
    public void run() {
      android.os.Process.setThreadPriority(
          android.os.Process.THREAD_PRIORITY_BACKGROUND
          + android.os.Process.THREAD_PRIORITY_MORE_FAVORABLE);
      if (preventNetworkOperations) {
        StrictMode.setThreadPolicy(
            new ThreadPolicy.Builder()
                .detectNetwork()
                .penaltyDeath()
                .build());
      }
      try {
        super.run();
      } catch (Throwable t) {
        uncaughtThrowableStrategy.handle(t);
      }
    }
  };
  threadNum++;
  return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:GlideExecutor.java


示例2: getCoreCountPre17

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
/**
 * Determines the number of cores available on the device (pre-v17).
 *
 * <p>Before Jellybean, {@link Runtime#availableProcessors()} returned the number of awake cores,
 * which may not be the number of available cores depending on the device's current state. See
 * https://stackoverflow.com/a/30150409.
 *
 * @return the maximum number of processors available to the VM; never smaller than one
 */
@SuppressWarnings("PMD")
private static int getCoreCountPre17() {
  // We override the current ThreadPolicy to allow disk reads.
  // This shouldn't actually do disk-IO and accesses a device file.
  // See: https://github.com/bumptech/glide/issues/1170
  File[] cpus = null;
  ThreadPolicy originalPolicy = StrictMode.allowThreadDiskReads();
  try {
    File cpuInfo = new File(CPU_LOCATION);
    final Pattern cpuNamePattern = Pattern.compile(CPU_NAME_REGEX);
    cpus = cpuInfo.listFiles(new FilenameFilter() {
      @Override
      public boolean accept(File file, String s) {
        return cpuNamePattern.matcher(s).matches();
      }
    });
  } catch (Throwable t) {
    if (Log.isLoggable(TAG, Log.ERROR)) {
      Log.e(TAG, "Failed to calculate accurate cpu count", t);
    }
  } finally {
    StrictMode.setThreadPolicy(originalPolicy);
  }
  return Math.max(1, cpus != null ? cpus.length : 0);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:RuntimeCompat.java


示例3: newThread

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
@Override
public synchronized Thread newThread(@NonNull Runnable runnable) {
  final Thread result = new Thread(runnable, "glide-" + name + "-thread-" + threadNum) {
    @Override
    public void run() {
      android.os.Process.setThreadPriority(DEFAULT_PRIORITY);
      if (preventNetworkOperations) {
        StrictMode.setThreadPolicy(
            new ThreadPolicy.Builder()
                .detectNetwork()
                .penaltyDeath()
                .build());
      }
      try {
        super.run();
      } catch (Throwable t) {
        uncaughtThrowableStrategy.handle(t);
      }
    }
  };
  threadNum++;
  return result;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:GlideExecutor.java


示例4: initializeStrictMode

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
private static void initializeStrictMode() {
    if (!strictModeInitialized) {
        if (SDK_INT >= GINGERBREAD) {
            ThreadPolicy.Builder threadPolicy = new ThreadPolicy.Builder();
            VmPolicy.Builder     vmPolicy     = new VmPolicy.Builder();

            threadPolicy.detectAll()
                        .penaltyLog();
            vmPolicy.detectAll()
                        .penaltyLog();

            if (STRICT_MODE_KILL_ON_ERROR) {
                threadPolicy.penaltyDeath();
                vmPolicy.penaltyDeath();
            }

            StrictMode.setThreadPolicy(threadPolicy.build());
            StrictMode.setVmPolicy(vmPolicy.build());

            strictModeInitialized = true;
        }
    }
}
 
开发者ID:blstream,项目名称:StudyBox_Android,代码行数:24,代码来源:DebugHelper.java


示例5: zzb

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
public static <T> T zzb(Callable<T> paramCallable)
{
  StrictMode.ThreadPolicy localThreadPolicy = StrictMode.getThreadPolicy();
  try
  {
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder(localThreadPolicy).permitDiskReads().permitDiskWrites().build());
    Object localObject2 = paramCallable.call();
    return localObject2;
  }
  catch (Throwable localThrowable)
  {
    zzb.e("Unexpected exception.", localThrowable);
    zzp.zzbL().zzb(localThrowable, true);
    return null;
  }
  finally
  {
    StrictMode.setThreadPolicy(localThreadPolicy);
  }
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:21,代码来源:zzja.java


示例6: calculateBestThreadCount

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
/**
 * Determines the number of cores available on the device.
 *
 * <p>{@link Runtime#availableProcessors()} returns the number of awake cores, which may not
 * be the number of available cores depending on the device's current state. See
 * http://goo.gl/8H670N.
 */
public static int calculateBestThreadCount() {
  // We override the current ThreadPolicy to allow disk reads.
  // This shouldn't actually do disk-IO and accesses a device file.
  // See: https://github.com/bumptech/glide/issues/1170
  ThreadPolicy originalPolicy = StrictMode.allowThreadDiskReads();
  File[] cpus = null;
  try {
    File cpuInfo = new File(CPU_LOCATION);
    final Pattern cpuNamePattern = Pattern.compile(CPU_NAME_REGEX);
    cpus = cpuInfo.listFiles(new FilenameFilter() {
      @Override
      public boolean accept(File file, String s) {
        return cpuNamePattern.matcher(s).matches();
      }
    });
  } catch (Throwable t) {
    if (Log.isLoggable(TAG, Log.ERROR)) {
      Log.e(TAG, "Failed to calculate accurate cpu count", t);
    }
  } finally {
    StrictMode.setThreadPolicy(originalPolicy);
  }

  int cpuCount = cpus != null ? cpus.length : 0;
  int availableProcessors = Math.max(1, Runtime.getRuntime().availableProcessors());
  return Math.min(MAXIMUM_AUTOMATIC_THREAD_COUNT, Math.max(availableProcessors, cpuCount));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:35,代码来源:GlideExecutor.java


示例7: enableStrictMode

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
private void enableStrictMode() {
	if (TESTING) {
		ThreadPolicy.Builder threadPolicy = new ThreadPolicy.Builder();
		threadPolicy.detectAll();
		threadPolicy.penaltyLog();
		StrictMode.setThreadPolicy(threadPolicy.build());
		VmPolicy.Builder vmPolicy = new VmPolicy.Builder();
		vmPolicy.detectAll();
		vmPolicy.penaltyLog();
		StrictMode.setVmPolicy(vmPolicy.build());
	}
}
 
开发者ID:rafjordao,项目名称:Nird2,代码行数:13,代码来源:SplashScreenActivity.java


示例8: resolveActivity

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
/**
 * Retrieves the single activity that matches the given intent, or null if none found.
 * @param intent The intent to query.
 * @return The matching activity.
 */
public ResolveInfo resolveActivity(Intent intent) {
    ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        return ContextUtils.getApplicationContext().getPackageManager().resolveActivity(
                intent, 0);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:15,代码来源:PackageManagerDelegate.java


示例9: getActivitiesThatCanRespondToIntent

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
/**
 * Retrieves the list of activities that can respond to the given intent.
 * @param intent The intent to query.
 * @return The list of activities that can respond to the intent.
 */
public List<ResolveInfo> getActivitiesThatCanRespondToIntent(Intent intent) {
    ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        return ContextUtils.getApplicationContext().getPackageManager().queryIntentActivities(
                intent, 0);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:15,代码来源:PackageManagerDelegate.java


示例10: getActivitiesThatCanRespondToIntentWithMetaData

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
/**
 * Retrieves the list of activities that can respond to the given intent. And returns the
 * activites' meta data in ResolveInfo.
 *
 * @param intent The intent to query.
 * @return The list of activities that can respond to the intent.
 */
public List<ResolveInfo> getActivitiesThatCanRespondToIntentWithMetaData(Intent intent) {
    ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        return ContextUtils.getApplicationContext().getPackageManager().queryIntentActivities(
                intent, PackageManager.GET_META_DATA);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:17,代码来源:PackageManagerDelegate.java


示例11: getServicesThatCanRespondToIntent

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
/**
 * Retrieves the list of services that can respond to the given intent.
 * @param intent The intent to query.
 * @return The list of services that can respond to the intent.
 */
public List<ResolveInfo> getServicesThatCanRespondToIntent(Intent intent) {
    ThreadPolicy oldPolicy = StrictMode.allowThreadDiskReads();
    try {
        return ContextUtils.getApplicationContext().getPackageManager().queryIntentServices(
                intent, 0);
    } finally {
        StrictMode.setThreadPolicy(oldPolicy);
    }
}
 
开发者ID:mogoweb,项目名称:365browser,代码行数:15,代码来源:PackageManagerDelegate.java


示例12: enableNasty

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private static Object enableNasty() {
	ThreadPolicy oldThreadPolicy = StrictMode.getThreadPolicy();
	StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
	StrictMode.setThreadPolicy(policy);
	return oldThreadPolicy;
}
 
开发者ID:vuze,项目名称:vuze-remote-for-android,代码行数:8,代码来源:RPC.java


示例13: revertNasty

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
private static void revertNasty(@Nullable ThreadPolicy oldPolicy) {
	if (oldPolicy == null) {
		return;
	}
	StrictMode.setThreadPolicy(oldPolicy);
}
 
开发者ID:vuze,项目名称:vuze-remote-for-android,代码行数:8,代码来源:RPC.java


示例14: permit

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
/**
 * @param policy
 * @param runnable
 * @return
 */
@TargetApi(VERSION_CODES.HONEYCOMB)
public void permit(final Policy.Thread policy, final Runnable runnable) {
    final ThreadPolicy oldPolicy = StrictMode.getThreadPolicy();
    final ThreadPolicy.Builder builder = new ThreadPolicy.Builder(oldPolicy);

    switch (policy) {
        case PermitAll: {
            builder.permitAll();
            break;
        }
        case PermitCustomSlowCalls: {
            if (AndroidUtils.isAtLeastHoneycomb()) {
                builder.permitCustomSlowCalls();
            }
            break;
        }
        case PermitDiskReads: {
            builder.permitDiskReads();
            break;
        }
        case PermitDiskWrites: {
            builder.permitDiskWrites();
            break;
        }
        case PermitNetwork: {
            builder.permitNetwork();
            break;
        }
    }

    StrictMode.setThreadPolicy(builder.build());

    if (runnable != null) {
        runnable.run();
    }

    StrictMode.setThreadPolicy(oldPolicy);
}
 
开发者ID:remelpugh,项目名称:android-shared,代码行数:44,代码来源:StrictModeHelper.java


示例15: reset

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
/**
 * @return The current instance of {@link StrictModeHelper}.
 */
public StrictModeHelper reset() {
    if (!AppHelper.with(context).isDebuggable()) {
        return this;
    }

    threadBuilder = new ThreadPolicy.Builder();
    vmBuilder = new VmPolicy.Builder();

    return this;
}
 
开发者ID:remelpugh,项目名称:android-shared,代码行数:14,代码来源:StrictModeHelper.java


示例16: enableStrictMode

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
private void enableStrictMode() {
	ThreadPolicy.Builder threadPolicy = new ThreadPolicy.Builder();
	threadPolicy.detectAll();
	threadPolicy.penaltyLog();
	StrictMode.setThreadPolicy(threadPolicy.build());

	VmPolicy.Builder vmPolicy = new VmPolicy.Builder();
	vmPolicy.detectAll();
	vmPolicy.penaltyLog();
	StrictMode.setVmPolicy(vmPolicy.build());
}
 
开发者ID:grote,项目名称:Transportr,代码行数:12,代码来源:MapActivity.java


示例17: onCreate

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
public void onCreate(Bundle savedInstanceState)
{
   super.onCreate(savedInstanceState);
   setContentView(R.layout.route);
   StrictMode.setThreadPolicy(ThreadPolicy.LAX); // get rid of NetworkOnMainThreadException

   try
   {
      MapView mapview = (MapView) findViewById(R.id.myMapView1);
      mapview.setBuiltInZoomControls(true);
      mapview.setClickable(true);
      mapview.setStreetView(true);
      if (Loader.isFullScreen)
         getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
      // get passed parameters
      Bundle extras = getIntent().getExtras();
      double latI = extras.getDouble("latI");
      double lonI = extras.getDouble("lonI");
      double latF = extras.getDouble("latF");
      double lonF = extras.getDouble("lonF");
      String scoords = extras.getString("coord");
      mapview.setSatellite(extras.getBoolean("sat"));
      GeoPoint srcGeoPoint = new GeoPoint((int) (latI * 1E6), (int) (lonI * 1E6));
      GeoPoint dstGeoPoint = new GeoPoint((int) (latF * 1E6), (int) (lonF * 1E6));
      List<GeoPoint> pairs = null;
      if (latI != 0 && lonI != 0 && latF != 0 && lonF != 0)
         pairs = getRoute(srcGeoPoint, dstGeoPoint);
      else // traversed points
      if (scoords != null)
      {
         String[] s = scoords.split(",");
         pairs = new ArrayList<GeoPoint>(s.length/2);
         for (int i = 0; i < s.length;)
            pairs.add(new GeoPoint((int)(Double.valueOf(s[i++])*1E6),(int)(Double.valueOf(s[i++])*1E6)));
      }
      if (pairs == null)
         throw new Exception("No lat/lon found");
      int color = Color.RED;
      int n = pairs.size();
      List<Overlay> overs = mapview.getOverlays();
      GeoPoint p1 = pairs.get(0);
      GeoPoint p2 = pairs.get(n-1);
      overs.add(new MyOverLay(p1,p1, 1));
      for (int i = 1; i < n; i++) // the last one would be crash
         overs.add(new MyOverLay(pairs.get(i-1), pairs.get(i), 2, color));
      overs.add(new MyOverLay(p2,p2, 3));
  
      // move the map to the given point
      mapview.getController().zoomToSpan(Math.abs(p1.getLatitudeE6() - p2.getLatitudeE6()), Math.abs(p1.getLongitudeE6() - p2.getLongitudeE6()));
      mapview.getController().animateTo(new GeoPoint(p1.getLatitudeE6() - ((p1.getLatitudeE6() - p2.getLatitudeE6())/2), p1.getLongitudeE6() - ((p1.getLongitudeE6() - p2.getLongitudeE6())/2)));
   }
   catch (Exception e)
   {
      AndroidUtils.handleException(e,false);
      finish();
   }
}
 
开发者ID:guilhermehazan,项目名称:TotalCrossSDK,代码行数:58,代码来源:RouteViewer.java


示例18: isLocalAvailable

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
public static boolean isLocalAvailable() {
	Object oldThreadPolicy = null;
	try {
		if (android.os.Build.VERSION.SDK_INT > 9) {
			// allow synchronous networking because we are only going to localhost
			// and it will return really fast (it better!)
			oldThreadPolicy = enableNasty();
		}

		String url = "http://localhost:9091/transmission/rpc?json="
				+ URLEncoder.encode("{\"method\":\"session-get\"}", "utf-8");

		BasicHttpParams basicHttpParams = new BasicHttpParams();
		HttpProtocolParams.setUserAgent(basicHttpParams,
			AndroidUtils.VUZE_REMOTE_USERAGENT);
		HttpConnectionParams.setConnectionTimeout(basicHttpParams, 200);
		HttpConnectionParams.setSoTimeout(basicHttpParams, 900);
		HttpClient httpclient = new DefaultHttpClient(basicHttpParams);

		// Prepare a request object
		HttpGet httpget = new HttpGet(url); // IllegalArgumentException

		// Execute the request
		HttpResponse response = httpclient.execute(httpget);

		if (response.getStatusLine().getStatusCode() == 409) {
			// Must be RPC!
			return true;
		}

	} catch (HttpHostConnectException ignore) {
		// Connection to http://localhost:9091 refused
	} catch (Throwable e) {
		Log.e("RPC", "isLocalAvailable", e);
	} finally {
		if (android.os.Build.VERSION.SDK_INT > 9) {
			revertNasty((ThreadPolicy) oldThreadPolicy);
		}
	}
	return false;
}
 
开发者ID:vuze,项目名称:vuze-remote-for-android,代码行数:42,代码来源:RPC.java


示例19: onCreate

import android.os.StrictMode.ThreadPolicy; //导入依赖的package包/类
@Override
public void onCreate() {
  super.onCreate();
  setThreadPolicy(new ThreadPolicy.Builder().detectAll().penaltyLog().build());
  setVmPolicy(new VmPolicy.Builder().detectAll().penaltyLog().build());
}
 
开发者ID:google,项目名称:agera,代码行数:7,代码来源:NotesApplication.java



注:本文中的android.os.StrictMode.ThreadPolicy类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DetailsOverviewRowPresenter类代码示例发布时间:2022-05-21
下一篇:
Java PlaceBuffer类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap