小编Răz*_*scu的帖子

为什么明确告诉我我的默认视图引擎没有定义?

我在后端使用nodejs和mongodb作为我正在开发的应用程序.我正在使用express来测试应用程序,我正在尝试使用ejs来呈现我的html文件.但是,我遇到了我的默认视图引擎未定义的问题.

这是我的app.js:

/**
* Module dependencies.
*/
var express = require('express')
   , routes = require('./routes')
   , user = require('./routes/user')
   , http = require('http')
   , path = require('path');
var conf = require('./conf');
var app = express();
var mongoose = require('mongoose');
   , Schema = mongoose.Schema
   , ObjectId = mongooseSchemaTypes.ObjectID;
var UserSchema = new Schema({})
   , User;
// all environments
app.set('port', process.env.PORT || 3000);
app.set('view engine', 'ejs');
app.engine('.html', require('ejs').renderFile());
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
// development only
if ('development' == app.get('env')) …
Run Code Online (Sandbox Code Playgroud)

ejs mongoose mongodb node.js express

15
推荐指数
1
解决办法
5万
查看次数

Scala Futures的核心速度很慢

对于一个研究项目,我编写了一个Scala应用程序,它使用一堆期货来进行并行计算.我注意到在我的本地机器(4核)上,代码运行速度比我们计算机科学研究所的多核服务器(64核)要快.现在我想知道为什么会这样.

任务详情

任务是创建随机布尔k-CNF公式,其中n个不同的变量随机分布在m个子句中,然后看看在不同的随机分布中,在哪个m/n组合中,公式可解的概率下降到50%以下.为此,我实现了概率k-SAT算法,子句生成器和其他一些代码.核心是一个函数,它将n和m作为生成器函数,运行100个期货并等待结果.该函数如下所示:

有问题的代码

def avgNonvalidClauses(n: Int, m: Int)(implicit clauseGenerator: ClauseGenerator) = {

    val startTime = System.nanoTime

    /** how man iteration to build the average **/
    val TRIES = 100

    // do TRIES iterations in parallel 
    val tasks = for (i <- 0 until TRIES) yield future[Option[Config]] {
        val clause = clauseGenerator(m, n)
        val solution = CNFSolver.probKSat(clause)
        solution
    }

    /* wait for all threads to finish and collect the results. we will only wait
     * at most TRIES * 100ms …
Run Code Online (Sandbox Code Playgroud)

performance scala future

11
推荐指数
1
解决办法
1413
查看次数

当可以避免时,需要在迭代时手动同步同步列表吗?

我的问题是关于synchronizedList方法集合类.

Javadocs说:

It is imperative that the user manually synchronize on the returned list when iterating over it:

List list = Collections.synchronizedList(new ArrayList());
      ...
synchronized(list) {
   Iterator i = list.iterator(); // Must be in synchronized block
   while (i.hasNext())
      foo(i.next());
}
Run Code Online (Sandbox Code Playgroud)

虽然其他方法不需要手动同步.我查看了Collections类的源代码,发现shyncronization已经处理了像add这样的所有方法

public boolean add(E e) {
   synchronized(list) {return c.add(e);}
}
Run Code Online (Sandbox Code Playgroud)

但不适用于迭代器方法.我认为迭代器方法也可以以与上述方法相同的方式处理同步(它可以避免额外的工作,即程序员的手动同步).我相信它背后肯定有一些具体的原因,但我错过了它?

public Iterator<E> iterator() {
   return c.iterator(); // Must be manually synched by user!
}
Run Code Online (Sandbox Code Playgroud)

一种避免程序员手动同步的方法

public Iterator<E> iterator() {
   synchronized(list) {
       return c.iterator(); // No need to manually …
Run Code Online (Sandbox Code Playgroud)

java collections synchronization list java.util.concurrent

7
推荐指数
1
解决办法
2704
查看次数