我有一个java应用程序,它使用Java Thread每1秒连接到MSSQL数据库查询一些信息,下面是伪
class PaintPage extends Component {
constructor(props) {
super(props);
this.state = {};
this.handleSubmit = this.handleSubmit.bind(this);
//Brads cool
}
handleSubmit(e) {
e.preventDefault();
Paint.insert({
brand: this.refs.brand.value,
color: this.refs.color.value,
sheen: this.refs.sheen.value,
room: this.refs.room.value
});
}
render() {
var paintArr = Paint.find().fetch();
paintArr.map((room, index) =>
<div className="row">
<div className="col-xs-2">
<li className="list-group-item text-center" key={room}>
{paintArr}
</li>
</div>
</div>
);
return (
<div>
<div className="row">
<div className="col-xs-4">
<ProductNav />
</div>
</div>
<form className="form" onSubmit={this.handleSubmit}>
<div className="row">
<div className="col-xs-4" />
<div className="col-xs-4">
<label htmlFor="brand" className="input">
Paint Brand
</label>
<div className="field">
<input
type="text"
name="brand"
className="form-control"
placeholder="Brand/Company"
ref="brand"
value={this.props.value}
onChange={this.props.onChange}
/>
</div>
</div>
</div>
<div className="row">
<div className="col-xs-4" />
<div className="col-xs-4">
<label htmlFor="color" className="input">
Color
</label>
<div className="field">
<input
type="text"
name="brand"
className="form-control"
placeholder="Color"
ref="color"
value={this.props.value}
onChange={this.props.onChange}
/>
</div>
</div>
</div>
<div className="row">
<div className="col-xs-4" />
<div className="col-xs-4">
<label htmlFor="brand" className="input">
Sheen
</label>
<div className="field">
<input
type="text"
name="brand"
className="form-control"
placeholder="Sheen"
ref="sheen"
value={this.props.value}
onChange={this.props.onChange}
/>
</div>
</div>
</div>
<div className="row">
<div className="col-xs-4" />
<div className="col-xs-4">
<label htmlFor="room" className="input">
Room
</label>
<div className="field">
<input
type="text"
name="room"
className="form-control"
placeholder="Room"
ref="room"
value={this.props.value}
onChange={this.props.onChange}
/>
</div>
</div>
</div>
<div className="row">
<div className="col-xs-12"> </div>
<input
className="btn btn-primary btn-lg button-buffer"
type="submit"
value="Input"
/>
</div>
</form>
<div>
<div>
<ul className="list-group">
{paintArr.toString()}
</ul>
</div>
</div>
</div>
);
}
}
export default PaintPage;
所以发生了什么,SQL Server最初为该查询分配了SPID 60,当java清理并关闭连接时,1秒后又要求连接执行相同的查询SQL Server分配回SPID 60
由于这个TempDB文件永远不会自由并继续增加。所以我的问题是:如何确保每次在sql server中获得新会话?这样tempDB就不会继续增加并保持空间。
答案 0 :(得分:0)
问题在于连接池设置和一个在1秒内保持池的java代码,因为该连接从未关闭。以下是我对JBOSS 5和mSSQL Server的设置
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>Base_nucleusdv</jndi-name>
<driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
<connection-url>jdbc:sqlserver://db;databaseName=ReportServices;</connection-url>
<security-domain>EncryptPassword</security-domain>
<!--pooling parameters-->
<min-pool-size>0</min-pool-size>
<max-pool-size>20</max-pool-size>
<idle-timeout-minutes>1</idle-timeout-minutes>
<query-timeout>60</query-timeout>
<track-statements>true</track-statements>
</local-tx-datasource>
</datasources>