coldfusion - null null error in SERVER structure -


i have server variable, structure of structures, highly accessed users (concurrency). values added , deleted very frequently. here small example of server variable. real 1 has more data.

<cfset server.structure = structnew()>  <cfset s = structnew()> <cfset structinsert(s, 'test11', 'value11', true)> <cfset structinsert(s, 'test12', 'value12', true)> <cfset structinsert(server.structure, 'test1', s, true)>  <cfset s = structnew()> <cfset structinsert(s, 'test21', 'value21', true)> <cfset structinsert(s, 'test22', 'value22', true)> <cfset structinsert(server.structure, 'test2', s, true)> 

every couple of hours, loop structure clean expired data. however, getting error "null null" while looping variable this:

<cfloop collection="#server.structure#" item="key">     <cfif structkeyexists(server.structure, key)>         <cfloop collection="#structfind(server.structure, key)#" item="key2">             <!--- , code here --->         </cfloop>     </cfif>      <cfif structcount(structfind(server.structure, key)) eq 0>         <cfset structdelete(server.structure, key, false)>     </cfif> </cfloop> 

i'm receiving error in first line of example. in line, exactly:

<cfloop collection="#server.structure#" item="key"> 

so tried approach. instead of looping 1 one, created array of keys , looped it. unfortunately, "null null" error happening there, in exact line:

<cfset arrayofkeys = structkeyarray(server.structure)> 

my first theory coldfusion can't handle concurrency level server variable has. tried use <cflock> here, while clearing variable, didn't work either. , can't have <cflock> variable being used , modified users because of load add (i believe).

i don't know... i'm out of ideas. why happening or have suffered problem before? , solution or workaround problem, or suggestion make code better, more welcome too.

thank much.

i tried use <cflock> here, while clearing variable, didn't work either. , can't have <cflock> variable being used , modified users because of load add (i believe).

this problem. if using server scope, must lock access (read , write). otherwise errors. that's long , short of it.

my first theory coldfusion can't handle concurrency level server variable has

well: no. coldfusion synchronise individual operations server scope (well: it's handled @ java level), , that's job begins , ends. it's your approach doesn't handle it. namely don't take steps mitigate race conditions in own code. assertion of yours:

i not locking access when work variable because collisions can't happen

is wrong. there's race condition in loop.

as others have hinted at, poor application architecture, , code facile.

just put data in database. that's databases for, , they're written in such way optimise sorts of operation trying (but not succeeding, obviously) achieve here.

i think case of premature optimisation: have had data in provisioned , designed db? or second-guessing problem? suspect it's latter. or db server not provisioned.

over , above database tier, use caching tier others have suggested.

but don't reinvent wheel, others have said.

the bottom line answer question you're getting errors because not correctly locking data, , have race conditions in code, making coldfusion trying access data have told there, subsequently have been changed. due code, not shortcoming in coldfusion.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -