Detecting the number of processors

System.Environment.ProcessorCount returns the number of logical processors http://msdn.microsoft.com/en-us/library/system.environment.processorcount.aspx For physical processor count you’d probably need to use WMI – the following metadata is supported in XP/Win2k3 upwards (Functionality enabled in SP’s prior to Vista/Win2k8). Win32_ComputerSystem.NumberOfProcessors returns physical count Win32_ComputerSystem.NumberOfLogicalProcessors returns logical (duh!) Be cautious that HyperThreaded CPUs appear identical to multicore’d CPU’s yet the performance … Read more

Getting all the total and available space on Android

Here is how you get internal storage sizes: StatFs statFs = new StatFs(Environment.getRootDirectory().getAbsolutePath()); long blockSize = statFs.getBlockSize(); long totalSize = statFs.getBlockCount()*blockSize; long availableSize = statFs.getAvailableBlocks()*blockSize; long freeSize = statFs.getFreeBlocks()*blockSize; Here is how you get external storage sizes (SD card size): StatFs statFs = new StatFs(Environment.getExternalStorageDirectory().getAbsolutePath()); long blockSize = statFs.getBlockSize(); long totalSize = statFs.getBlockCount()*blockSize; long availableSize … Read more

Setting up Eclipse with JRE Path

You can add this line to eclipse.ini : -vm D:/work/Java/jdk1.6.0_13/bin/javaw.exe <– change to your JDK actual path -vmargs <– needs to be after -vm <path> But it’s worth setting JAVA_HOME and JRE_HOME anyway because it may not work as if the path environment points to a different java version. Because the next one to complain … Read more

Spring Boot – Environment @Autowired throws NullPointerException

Though your specific problem is solved, here’s how to get Environment in case Spring’s autowiring happens too late. The trick is to implement org.springframework.context.EnvironmentAware; Spring then passes environment to setEnvironment() method. This works since Spring 3.1. An example: @Configuration @PropertySource(“classpath:myProperties.properties”) public class MyConfiguration implements EnvironmentAware { private Environment environment; @Override public void setEnvironment(final Environment environment) … Read more

Autowired Environment is null

Autowiring happens later than load() is called (for some reason). A workaround is to implement EnvironmentAware and rely on Spring calling setEnvironment() method: @Configuration @ComponentScan(basePackages = “my.pack.offer.*”) @PropertySource(“classpath:OfferService.properties”) public class PropertiesUtil implements EnvironmentAware { private Environment environment; @Override public void setEnvironment(final Environment environment) { this.environment = environment; } @Bean public String load(String propertyName) { return … Read more

What is the difference between parent.frame() and parent.env() in R; how do they differ in call by reference?

parent.env is the environment in which a closure (e.g., function) is defined. parent.frame is the environment from which the closure was invoked. f = function() c(f=environment(), defined_in=parent.env(environment()), called_from=parent.frame()) g = function() c(g=environment(), f()) and then > g() $g <environment: 0x14060e8> $f <environment: 0x1405f28> $defined_in <environment: R_GlobalEnv> $called_from <environment: 0x14060e8> I’m not sure when a mere … Read more

How to set active spring 3.1 environment profile via a properites file and not via an env variable or system property

In web.xml <context-param> <param-name>spring.profiles.active</param-name> <param-value>profileName</param-value> </context-param> Using WebApplicationInitializer This approach is used when you don’t have a web.xml file in Servlet 3.0 environment and are bootstrapping the Spring completely from Java: class SpringInitializer extends WebApplicationInitializer { void onStartup(ServletContext container) { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.getEnvironment().setActiveProfiles(“profileName”); rootContext.register(SpringConfiguration.class); container.addListener(new ContextLoaderListener(rootContext)); } } Where SpringConfiguration class is … Read more