我正在使用 Spring 项目实现 ehcache 但没有成功。
这是我在 applicationContext.xml 中的设置:
<ehcache:annotation-driven />
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="/META-INF/spring/ehcache.xml" />
</bean>
Run Code Online (Sandbox Code Playgroud)
这是我在 ehcache.xml 中的设置:
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<diskStore path="java.io.tmpdir" />
<defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />
<cache name="listTop" maxElementsInMemory="10" eternal="true" overflowToDisk="false" />
</ehcache>
Run Code Online (Sandbox Code Playgroud)
这是我的实现类:
@Cacheable(cacheName="listTop")
public void listTop(News news, String regionCode, Integer count, Integer categoryId, String listType){
//code here//
}
Run Code Online (Sandbox Code Playgroud)
我收到以下消息,似乎未配置缓存:
1827 DEBUG net.sf.ehcache.config.BeanHandler - Ignoring ehcache attribute xmlns:xsi
1827 DEBUG net.sf.ehcache.config.BeanHandler - Ignoring ehcache attribute xsi:noNamespaceSchemaLocation
1828 DEBUG net.sf.ehcache.config.DiskStoreConfiguration - Disk Store Path: …Run Code Online (Sandbox Code Playgroud) 我正在创建一个有一些线程的应用程序,我想关闭它。我试过:
System.exit(0);
Run Code Online (Sandbox Code Playgroud)
但应用程序会自行重启。
请帮帮我,谢谢。
编辑:
OnDestroy 代码:
@Override
public void onDestroy(){
android.os.Process.killProcess(android.os.Process.myPid());
}
Run Code Online (Sandbox Code Playgroud)
OnOptionsItemClicked:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item1:
startActivity(new Intent(this, ConnActivity.class));
finish();
break;
case R.id.item2:
android.os.Process.killProcess(android.os.Process.myPid());
System.exit(0);
break;
case R.id.item3:
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Mensaje al servidor");
alert.setMessage("Enviar mensaje al servidor");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Enviar", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString(); …Run Code Online (Sandbox Code Playgroud) 鉴于以下代码,我得到了null(我想要的是"1234").但我希望有一张地图可以将关键视为等于,如果内容int[]是等于(而不是考虑引用int[]),我应该怎么做?
HashMap<int[], String> maps=new HashMap<int[], String>();
int[] i=new int[]{1,2,3};
int[] j=new int[]{1,2,3};
maps.put(i,"1234");
System.out.print(maps.get(j));
Run Code Online (Sandbox Code Playgroud)
我打开任何允许保持int[]为关键(包括TreeMap)等的地图,其边缘条件是,如果这不妨碍地图访问时间的有效性.
我一直在研究实时应用程序,并注意到一些OOP设计模式在Python中引入了令人难以置信的开销(用2.7.5测试).
简单明了,为什么当字典被另一个对象封装时,字典值的简单访问方法需要花费近5倍的时间?
例如,运行下面的代码,我得到:
Dict Access: 0.167706012726
Attribute Access: 0.191128969193
Method Wrapper Access: 0.711422920227
Property Wrapper Access: 0.932291030884
Run Code Online (Sandbox Code Playgroud)
可执行代码:
class Wrapper(object):
def __init__(self, data):
self._data = data
@property
def id(self):
return self._data['id']
@property
def name(self):
return self._data['name']
@property
def score(self):
return self._data['score']
class MethodWrapper(object):
def __init__(self, data):
self._data = data
def id(self):
return self._data['id']
def name(self):
return self._data['name']
def score(self):
return self._data['score']
class Raw(object):
def __init__(self, id, name, score):
self.id = id
self.name = name
self.score = score
data = {'id': …Run Code Online (Sandbox Code Playgroud) 我用
func formatAmount(number:NSNumber) -> String {
let formatter = NSNumberFormatter()
formatter.numberStyle = .CurrencyStyle
return formatter.stringFromNumber(number)!
}
Run Code Online (Sandbox Code Playgroud)
将数字更改为货币格式化字符串,但我需要删除格式并获取只是数字,我需要删除逗号和货币符号.有什么具体的方法吗?请告诉我.
我试过了
func removeFormatAmount(string:String) -> NSNumber {
let formatter = NSNumberFormatter()
formatter.numberStyle = .NoStyle
formatter.currencySymbol = .None
formatter.currencyGroupingSeparator = .None
return formatter.numberFromString(string)!
}
Run Code Online (Sandbox Code Playgroud)
这给了我零价值.
更新 我发现,如果文本不包含$ sign,那么使用货币格式化将给出nil值,所以我所做的就是
if string.containsString("$") {
formatter.numberStyle = .CurrencyStyle
}
return formatter.numberFromString(string)?.floatValue
Run Code Online (Sandbox Code Playgroud)
现在它给了我很好的结果.
我有一个B和C类,它们都扩展到A类:
public class B extends A {...}
public class C extends A {...}
Run Code Online (Sandbox Code Playgroud)
如何以这种方式将Java泛型与HashMap一起使用?
B b = new B();
C c = new C();
Map<String, ? extends A> map = new HashMap<String, A>();
map.put("B", b);
map.put("C", c);
Run Code Online (Sandbox Code Playgroud)
Eclipse始终显示错误:
方法put(String,capture#1-of?extends A)在Map类型中不适用于参数(String,B)
和
方法put(String,capture#1-of?extends A)在Map类型中不适用于参数(String,C)