1.如何把一个字符串转成数字java
第一位3 if("3".equals("3")) {value = 3} 第二位 if("2".equals(str)){value = 2*10 + value}
2 单利,如何确保一个类是单利spring
public class Singleton { private static Singleton uniqueInstance = null; private Singleton() { // Exists only to defeat instantiation. } public static Singleton getInstance() { if (uniqueInstance == null) { uniqueInstance = new Singleton(); } return uniqueInstance; } // Other methods... }
可是以上代码并无考虑到单例模式在并发状况下的场景数组
单例对象的初始化同步并发
public class GlobalConfig { private static GlobalConfig instance = null; private Vector properties = null; private GlobalConfig() { //Load configuration information from DB or file //Set values for properties } private static synchronized void syncInit() { if (instance == null) { instance = new GlobalConfig(); } } public static GlobalConfig getInstance() { if (instance == null) { syncInit(); } return instance; } public Vector getProperties() { return properties; } }
单例对象的属性更新同步app
public class GlobalConfig { private static GlobalConfig instance; private Vector properties = null; private boolean isUpdating = false; private int readCount = 0; private GlobalConfig() { //Load configuration information from DB or file //Set values for properties } private static synchronized void syncInit() { if (instance == null) { instance = new GlobalConfig(); } } public static GlobalConfig getInstance() { if (instance==null) { syncInit(); } return instance; } public synchronized void update(String p_data) { syncUpdateIn(); //Update properties } private synchronized void syncUpdateIn() { while (readCount > 0) { try { wait(); } catch (Exception e) { } } } private synchronized void syncReadIn() { readCount++; } private synchronized void syncReadOut() { readCount--; notifyAll(); } public Vector getProperties() { syncReadIn(); //Process data syncReadOut(); return properties; } }
3.有个n整数,存储在数组array中,使其前面各数顺序向后移动m个位置,最后的m个数变成最前面的m个数,并输出spa
取模函code
4.spring如何在类里面得到applicatoncontextorm
1.建立一个类并让其实现orgntext.ApplicationContextAware接口来让Spring在启动的时候为咱们注入ApplicationContext对象. 示例代码: import org.springframework.beans.BeansException; import orgntext.ApplicationContext; import orgntext.ApplicationContextAware; public class MyApplicationContextUtil implements ApplicationContextAware { private static ApplicationContext context; //声明一个静态变量保存 public void setApplicationContext(ApplicationContext contex) throws BeansException { ntext=contex; } public static ApplicationContext getContext(){ return context; } } 2.在applicationContext.xml文件中配置此bean,以便让Spring启动时自动为咱们注入ApplicationContext对象. 例: <!-- 这个bean主要是为了获得ApplicationContext 因此它不须要其它属性--> <bean class="org.ing.springutil.MyApplicationContextUtil"></bean> 3.有了这个ApplicationContext以后咱们就能够调用其getBean("beanName")方法来获得由Spring 管理全部对象.
5 spring如何解析配置文件,spring如何处理请求的。xml