接口没有注册,导致构造的时候出错

今天在做MVC项目的时候,使用微软企业库的缓存接口icachemanager,抛出如下异常

The current type, Microsoft.Practices.EnterpriseLibrary.Caching.ICacheManager, is an interface and cannot be constructed. Are you missing a type mapping?

 

 

经过检查,发现要在webconfig里面注册

  <configSections>

  <section name="cachingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Caching.Configuration.CacheManagerSettings, Microsoft.Practices.EnterpriseLibrary.Caching" requirePermission="false"/>

 

 

光using还没有用

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这段代码存在一些问题。首先,你创建了两个 `Delayunnable` 实例,但没有将它们作为线程启动,而是直接调用了 `run()` 方法,这只是普通的方法调用,并不会启动新线程。其次,你在主线程中调用了 `Thread.sleep(1000)`,这会导致主线程阻塞,而不是让 `thread1` 和 `thread2` 延迟执行。 如果你想要启动新线程并让它们延迟执行,可以使用 `Thread` 类或者 `ExecutorService` 接口来实现。 以下是使用 `Thread` 类的示例代码: ```java package java9; class DelayRunnable implements Runnable { private int delay; public DelayRunnable(int delay) { this.delay = delay; } @Override public void run() { try { Thread.sleep(delay); } catch (InterruptedException e) { System.out.println("线程出错!"); } System.out.println("延迟 " + delay + " 毫秒后执行"); } } public class MyRunnable { public static void main(String args[]) { DelayRunnable thread1 = new DelayRunnable(2000); DelayRunnable thread2 = new DelayRunnable(3000); Thread t1 = new Thread(thread1); Thread t2 = new Thread(thread2); t1.start(); t2.start(); } } ``` 在这个示例中,我们创建了一个 `DelayRunnable` 类来表示需要延迟执行的任务。我们在构造函数中传入一个延迟时间(以毫秒为单位),然后在 `run()` 方法中调用 `Thread.sleep()` 方法来让线程休眠指定的时间。在主线程中,我们创建了两个 `DelayRunnable` 实例,并将它们分别封装成一个新的 `Thread` 对象,最后调用 `start()` 方法启动这两个线程。 你也可以使用 `ExecutorService` 接口来实现线程池和异步执行: ```java package java9; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; class DelayRunnable implements Runnable { private int delay; public DelayRunnable(int delay) { this.delay = delay; } @Override public void run() { try { Thread.sleep(delay); } catch (InterruptedException e) { System.out.println("线程出错!"); } System.out.println("延迟 " + delay + " 毫秒后执行"); } } public class MyRunnable { public static void main(String args[]) { DelayRunnable task1 = new DelayRunnable(2000); DelayRunnable task2 = new DelayRunnable(3000); ExecutorService executor = Executors.newFixedThreadPool(2); executor.execute(task1); executor.execute(task2); executor.shutdown(); } } ``` 在这个示例中,我们创建了两个 `DelayRunnable` 实例,并将它们封装成一个新的 `ExecutorService` 对象。我们使用 `newFixedThreadPool(2)` 方法创建一个大小为 2 的线程池,然后调用 `execute()` 方法来提交任务。最后,我们调用 `shutdown()` 方法关闭线程池,等待所有任务执行完毕。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值