我不是Node程序员,但我对单线程非阻塞IO模型的工作原理感兴趣.在我阅读了文章理解-node-js-event-loop之后,我真的很困惑.它给出了该模型的一个例子:
c.query(
'SELECT SLEEP(20);',
function (err, results, fields) {
if (err) {
throw err;
}
res.writeHead(200, {'Content-Type': 'text/html'});
res.end('<html><head><title>Hello</title></head><body><h1>Return from async DB query</h1></body></html>');
c.end();
}
);
Run Code Online (Sandbox Code Playgroud)
这是一个问题.当有两个请求A(至上)和B,由于只有一个线程,服务器端程序将处理请求的第一:做SQL查询这是一个睡眠声明站立I/O等待.并且程序停留在I/O等待,并且无法执行呈现网页的代码.程序会在等待期间切换到请求B吗?在我看来,由于单线程模型,没有办法从一个请求切换另一个请求.但是示例代码的标题说"除了代码之外,所有内容都是并行运行".(PS我不确定我是否误解了代码,因为我从未使用过Node.)节点如何在等待期间切换到B?你能用一种简单的方法解释Node的单线程非阻塞IO模型吗?如果你能帮助我,我将不胜感激.:)
当我尝试使用命令行mysql -h <remote-ip> -u any_existing_users -p或任何其他mysql客户端(如phpmyadmin)连接远程MySQL服务器时,它不起作用,错误提示是
ERROR 2003 (HY000) Can't connect to MySQL server on '<remote-ip>' (61)
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试ssh <remote-ip>在本地连接MySQL时mysql -u root -p,没有问题.
这是user table(SELECT User, Host FROM mysql.user;)的一部分:
+------------------+----------------+
| User | Host |
+------------------+----------------+
| root | % |
| other_users | <remote-ip> |
| root | localhost |
+------------------+----------------+
Run Code Online (Sandbox Code Playgroud)
这是iptable:
Chain INPUT (policy ACCEPT)
num target prot opt source destination
1 RH-Firewall-1-INPUT all -- 0.0.0.0/0 0.0.0.0/0
Chain FORWARD (policy ACCEPT) …Run Code Online (Sandbox Code Playgroud) 最近,我处理了从MySQL数据库中检索大量数据的数据,这些数据包含数千条记录.由于这是我第一次处理这么大的数据集,所以我没有考虑SQL语句的效率.问题来了.
以下是数据库的表格(它只是课程系统的简单数据库模型):
课程:
+-----------+---------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+---------------------+------+-----+---------+----------------+
| course_id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(20) | NO | | NULL | |
| lecturer | varchar(20) | NO | | NULL | |
| credit | float | NO | | NULL | |
| week_from | tinyint(3) unsigned | NO | | NULL | |
| week_to | …Run Code Online (Sandbox Code Playgroud) 我已经阅读了RFC 2616 - sec14.26和RFC 2616 - sec13.3.3很长一段时间了,但我仍然不确定我是否理解正确.
第14.26节指出
如果任何实体标签与在该资源上对类似GET请求(没有If-None-Match标头)的响应中返回的实体的实体标签匹配,或者如果给出"*"且任何当前标签对于该资源存在实体,那么服务器必须不执行所请求的方法,除非要求这样做,因为资源的修改日期与请求中的If-Modified-Since头字段中提供的日期不匹配.相反,如果请求方法是GET或HEAD,则服务器应该响应304(未修改)响应,包括匹配的其中一个实体的缓存相关头字段(特别是ETag).
,
如果没有任何实体标签匹配,则服务器可以执行所请求的方法,就像If-None-Match头字段不存在一样,但是也必须忽略请求中的任何If-Modified-Since头字段.也就是说,如果没有实体标签匹配,那么服务器绝不能返回304(未修改)响应.
第13.3.3节指出
HTTP/1.1源服务器,在接收到包括最后修改日期(例如,在If-Modified-Since或If-Unmodified-Since头字段中)和一个或多个实体标签(例如,在If-Match,If-None-Match或If-Range头字段)作为缓存验证器,除非这样做与请求中的所有条件头字段一致,否则不得返回304(未修改)的响应状态.
我很困惑无条件兼容的 HTTP服务器是否应该响应客户端请求(GET/ HEAD)
If-Modified-Since匹配,但If-None-Match没有.If-None-Match匹配,但If-Modified-Since不匹配.根据第14.26节,在第一种情况下应返回304 Not Modified,在第二种情况下应返回200 OK,因为If-Modified-Since忽略.
但是第13.3.3节说"它不能返回304(未修改)的响应状态,除非这样做与请求中的所有条件头字段一致." ,意味着在两种情况下都应该返回200 OK.
我在将由Netbeans创建的maven项目导入IDEA 12时遇到问题.在pom中写入的依赖项工件不起作用.它告诉我"无法在"import org.springframework.xxx;"上解析符号'springframework'".当我运行它时,它表示org.springframework.xxx不存在.这是pom文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cn.edu.seu.cose.jellyjolly</groupId>
<artifactId>jellyjolly-openshift-dist</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>Jelly Jolly Openshift Distribution</name>
<organization>
<name>College of Software Engineering, Southeast University</name>
<url>http://cose.seu.edu.cn/</url>
</organization>
<repositories>
<repository>
<id>eap</id>
<url>http://maven.repository.redhat.com/techpreview/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>maven-restlet</id>
<name>Public online Restlet repository</name>
<url>http://maven.restlet.org</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>eap</id>
<url>http://maven.repository.redhat.com/techpreview/all</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<netbeans.hint.license>gpl30</netbeans.hint.license>
</properties>
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<version>3.0.0.Final-redhat-1</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId> …Run Code Online (Sandbox Code Playgroud) HTML中的表单就像
...
<form method="post" action="/foobar">
<input type="file" name="attachment" />
<input type="text" name="foo" />
... other input fields
</form>
Run Code Online (Sandbox Code Playgroud)
而Servlet就像
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String attachment = request.getParameter("attachement");
String foo = request.getParameter("foo");
// get other parameters from the request
// and get the attachment file
}
Run Code Online (Sandbox Code Playgroud)
而且我在想
是否有任何方法不使用第三方库从HttpServletRequest对象中获取文件?
什么request.getParameter("attachement")回报?是文件名还是其他什么?
二进制输入是由Web容器自动存储在文件系统中还是暂时存储在内存中?
我知道git push origin master会让Openshift将应用程序重新部署到新版本.
但我的情况是我的Tomcat应用程序依赖于另一个子模块maven项目,它们都是快照.
一旦它的子模块项目发生变化(Tomcat应用程序保持不变),git push origin master它根本不起作用(Everything up-to-date)当然,Openshift不会重新部署我的应用程序,这意味着它不会更新最新的子模块快照工件为了我.
那么,如何解决这个问题呢?我曾尝试rhc restart和rhc reload,但他们不工作.有一些命令rhc redeploy吗?
我曾经写过一个synchronized像以下一样的块:
synchronized(foobar) {
// do something
}
Run Code Online (Sandbox Code Playgroud)
但是,最近我看到有人写道:
synchronized(foobar) {
// do something
foobar.notifyAll();
}
Run Code Online (Sandbox Code Playgroud)
有foobar.notifyAll();必要吗?如果我省略它会怎么样?
由于Web应用程序的开发通常分为前端开发和后端开发,但前端的一些代码在后端通常是相同的(ASP、PHP、JSP或其他服务器端模板)引擎中包含大量由前端开发人员编写的 HTML),后端开发人员需要做的是将 HTML 代码合并到他们的 ASP、PHP、JSP 或其他服务器端模板中。
如果前端的开发先于后端的开发,那么效果就很好。但是当前端和后端同时开发时(总是这样),问题就来了。当前端发生变化时,后端开发人员需要不断更改他的模板代码。
那么,我的问题是,有没有什么方法可以将HTML代码自动合并到后端模板中,从而使前后端的集成更加无缝和轻松。
这是我第一次使用 Maven 在 Glassfish 服务器上部署 Web 应用程序。
我一步一步执行以下maven目标:
mvn glassfish:create-domain -P glassfishmvn glassfish:start-domain -P glassfishmvn glassfish:deploy -P glassfish一切正常,直到第三步 ( glassfish:deploy) 并且错误消息是
[ERROR] remote failure: Error occurred during deployment: Exception while deploying the app [herald-web-services] : There is no web component by the name of default here.. Please see server.log for more details.
[ERROR] Deployment of /Users/Ray/workspace/herald-web-services/target/herald-web-services-1.1-SNAPSHOT.war failed.
[ERROR] For more detail on what might be causing the problem try running maven with the --debug option
[ERROR] …Run Code Online (Sandbox Code Playgroud)