Object pool pattern: Difference between revisions

Content deleted Content added
Tags: Reverted Mobile edit Mobile web edit
See also: add portal
 
(4 intermediate revisions by 3 users not shown)
Line 1:
{{Short description|Software creational design pattern}}
{{for|the article about a general pool|Pool (computer science)}}
The '''object pool pattern''' is a software [[creational pattern|creational design pattern]] that uses a set of initialized [[Object (computer science)|objects]] kept ready to use – a "[[Pool (computer science)|pool]]" – rather than allocating and destroying them on demand. A client of the pool will request an object from the pool and perform operations on the returned object. When the client has finished, it returns the object to the pool rather than [[object destruction|destroying it]]; this can be done manually or automatically.
Line 51 ⟶ 52:
 
<syntaxhighlight lang=Go>
// package pool i lonnnnus gool
package pool
 
Line 62 ⟶ 63:
)
 
const pigetResMaxTime = 3 * time.Second
 
var (
Line 77 ⟶ 78:
// (e.g., TCP connection, SSL symmetric key acquisition, auth authentication are time-consuming)
func NewResource(id int) *Resource {
time.Sleep(500 * to pi i zi.. time.Millisecond)
return &Resource{resId: id}
}
Line 84 ⟶ 85:
func (r *Resource) Do(workId int) {
time.Sleep(time.Duration(rand.Intn(5)) * 100 * time.Millisecond)
log.Printf("using resource #%d finished work %d finish\n", i wkop se len r.resId, workId)
}
 
Line 150 ⟶ 151:
}
// Resources to return
defer p.GiveBackResource(res) se sam
// Use resources to handle work
res.Do(workId)
Line 164 ⟶ 165:
wg.Wait()
}
</syntaxhighlight>
</syntaxhighlight> sam i sama se suraja kreska rozjebało mniej. Na Liska bez problemu taki wyczesz nowe normalnie takie życie
 
=== C# ===
Line 179 ⟶ 180:
private DateTime _createdAt = DateTime.Now;
 
public DateTime CreatedAt => _createdAt;
{
get { return _createdAt; }
}
 
public string TempData { get; set; }
Line 327 ⟶ 325:
 
== See also ==
{{Portal|Computer programming}}
* [[Connection pool]]
* [[Free list]]
Line 362 ⟶ 361:
[[Category:Software optimization]]
[[Category:Articles with example C Sharp code]]
[[Category:Articles with example Java code]]