NutzCN Logo
问答 使用了mongodb插件,上传多个文件后,没报错,但导致系统
发布于 1598天前 作者 dalichuifeng 1236 次浏览 复制 上一个帖子 下一个帖子
标签:
@AdaptBy(type = UploadAdaptor.class, args = {"ioc:fileUpload"})
    @POST
    @At({ "/file/?", "/file"})
    @Ok("json")
    @Filters({@By(type=CrossOriginFilter.class)})
    public Object fileUpload(@Param("Filedata") TempFile tf, @Param("wjid") String wjid, HttpServletRequest req,
                             @Param("disksymbol")String disksymbol,AdaptorErrorContext err) throws Exception {
        PropertiesUtil po = new PropertiesUtil("upload.properties");
        String uploadtype = po.readProperty("uploadtype");
        Result re = new Result();
        if(disksymbol!=null&&!disksymbol.equals("")){
            req.setAttribute("disksymbol", disksymbol);
        }
        if (err != null && err.getAdaptorErr() != null) {
            return NutMap.NEW().addv("code", 1).addv("msg", "文件不合法");
        } else if (tf == null) {
            return Result.error("空文件");
        } else {
            if (uploadtype != null && !uploadtype.equals("")) {
                switch (uploadtype) {
                    case "1":
                        re = localhostfile.executeUpload(tf, req);
                        break;
					/*case "ftp":
					ftpfile.executeUpload(tf, req);
					break;*/
                    case "2":
                        mongofile.readyMongo();
                        re = mongofile.executeUpload(tf, req);
                        break;
                    case "3":
                        re = dbfile.executeUpload(tf, req);
                    default:
                        break;
                }
                return re;

            } else {
                return Result.error("配置文件错误");
            }
        }
    }

@IocBean
public class MongoFile extends FileAbstract {

	@Inject
	MongoServiceImp mongoService;
	public void readyMongo(){
		mongoService.initMongo();
	}

--------------------------------------------------------
public void initMongo(){
Ioc ioc = new NutIoc(new JsonLoader("config/ioc/mongodb.json"));
this.zMongo = ioc.get(ZMongo.class);
//this.zMongo = (ZMongo) Mvcs.ctx().get("zMongo");
this.zMoDB = ioc.get(ZMoDB.class, "zMoDB");
this.zMoCoUser = ioc.get(ZMoCo.class, "zMoCoUser");
this.zMoCoDir = ioc.get(ZMoCo.class, "zMoCoDir");
}

8 回复

那,这是上传问题呢?还是mongodb问题呢?

上传的,mongodb别的站点也使用了。我还把站点给分离到两个tomcat,就是上传这个卡

打印的东西

2019-12-16 14:51:12,237 com.mongodb.diagnostics.logging.SLF4JLogger.debug(SLF4JL
ogger.java:56) DEBUG - Checking status of 198.87.118.7:27017
2019-12-16 14:51:12,238 com.mongodb.diagnostics.logging.SLF4JLogger.debug(SLF4JL
ogger.java:56) DEBUG - Updating cluster description to {type=STANDALONE, server
s=[{address=198.87.118.7:27017, type=STANDALONE, roundTripTime=1.1 ms, state=CON
NECTED}]
2019-12-16 14:51:12,241 com.mongodb.diagnostics.logging.SLF4JLogger.debug(SLF4JL
ogger.java:56) DEBUG - Checking status of 198.87.118.7:27017
2019-12-16 14:51:12,242 com.mongodb.diagnostics.logging.SLF4JLogger.debug(SLF4JL
ogger.java:56) DEBUG - Updating cluster description to {type=STANDALONE, server
s=[{address=198.87.118.7:27017, type=STANDALONE, roundTripTime=1.5 ms, state=CON
NECTED}]
2019-12-16 14:51:12,244 com.mongodb.diagnostics.logging.SLF4JLogger.debug(SLF4JL
ogger.java:56) DEBUG - Checking status of 198.87.118.7:27017
2019-12-16 14:51:12,245 com.mongodb.diagnostics.logging.SLF4JLogger.debug(SLF4JL
ogger.java:56) DEBUG - Updating cluster description to {type=STANDALONE, server
s=[{address=198.87.118.7:27017, type=STANDALONE, roundTripTime=1.2 ms, state=CON
NECTED}]

或者能不能给一个连接mongodb限制连接数的demo

@IocBean
public class MongoIocBeanMaker {

@Inject
protected PropertiesProxy conf;

@IocBean(name="mongoClient")
public MongoClient createMongoClient() {
    MongoClientOptions.Builder builder = MongoClientOptions.builder();
    builder.maxWaitTime(1500);
    MongoClientOptions clientOptions = builder.build();
    ServerAddress address = new ServerAddress(conf.get("mongo.host"), conf.getInt("mongo.port"));
    return new MongoClient(address, clientOptions);
}

@IocBean(name="zMongo")
public ZMongo createZMongo(@Inject MongoClient client) {
    return ZMongo.me(client);
}

}

文件上传多了会不会卡顿,内存没释放,图片没清理

添加回复
请先登陆
回到顶部